From 60ce1916f6ada2fbef861bdadebf030bf68c3b8e Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Mon, 24 Jun 2013 16:46:42 -0700 Subject: [PATCH] Code cleanup: move request code to AbstractSendToGoogleActivity --- .../AbstractSendToGoogleActivity.java | 21 +++++++++++-------- .../io/sendtogoogle/SendToGoogleUtils.java | 10 ++------- .../SendSpreadsheetsAsyncTask.java | 6 +++--- .../settings/GoogleSettingsActivity.java | 6 +++--- .../mytracks/endtoendtest/GoogleUtils.java | 2 +- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/AbstractSendToGoogleActivity.java b/MyTracks/src/com/google/android/apps/mytracks/AbstractSendToGoogleActivity.java index 9c2d73f19..3f2171871 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/AbstractSendToGoogleActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/AbstractSendToGoogleActivity.java @@ -71,7 +71,10 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv private static final String TAG = AbstractMyTracksActivity.class.getSimpleName(); private static final String SEND_REQUEST_KEY = "send_request_key"; - + private static final int DRIVE_REQUEST_CODE = 0; + private static final int FUSION_TABLES_REQUEST_CODE = 1; + private static final int SPREADSHEETS_REQUEST_CODE = 2; + private SendRequest sendRequest; @Override @@ -169,11 +172,11 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv if (intent != null) { int requestCode; if (scope.equals(SendToGoogleUtils.DRIVE_SCOPE)) { - requestCode = SendToGoogleUtils.DRIVE_PERMISSION_REQUEST_CODE; + requestCode = DRIVE_REQUEST_CODE; } else if (scope.equals(SendToGoogleUtils.FUSION_TABLES_SCOPE)) { - requestCode = SendToGoogleUtils.FUSION_TABLES_PERMISSION_REQUEST_CODE; + requestCode = FUSION_TABLES_REQUEST_CODE; } else { - requestCode = SendToGoogleUtils.SPREADSHEET_PERMISSION_REQUEST_CODE; + requestCode = SPREADSHEETS_REQUEST_CODE; } startActivityForResult(intent, requestCode); } else { @@ -185,7 +188,7 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { - case SendToGoogleUtils.DRIVE_PERMISSION_REQUEST_CODE: + case DRIVE_REQUEST_CODE: SendToGoogleUtils.cancelNotification(this, SendToGoogleUtils.DRIVE_NOTIFICATION_ID); if (resultCode == Activity.RESULT_OK) { onDrivePermissionSuccess(); @@ -193,7 +196,7 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv onPermissionFailure(); } break; - case SendToGoogleUtils.FUSION_TABLES_PERMISSION_REQUEST_CODE: + case FUSION_TABLES_REQUEST_CODE: SendToGoogleUtils.cancelNotification(this, SendToGoogleUtils.FUSION_TABLES_NOTIFICATION_ID); if (resultCode == Activity.RESULT_OK) { onFusionTablesSuccess(); @@ -201,8 +204,8 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv onPermissionFailure(); } break; - case SendToGoogleUtils.SPREADSHEET_PERMISSION_REQUEST_CODE: - SendToGoogleUtils.cancelNotification(this, SendToGoogleUtils.SPREADSHEET_NOTIFICATION_ID); + case SPREADSHEETS_REQUEST_CODE: + SendToGoogleUtils.cancelNotification(this, SendToGoogleUtils.SPREADSHEETS_NOTIFICATION_ID); if (resultCode == Activity.RESULT_OK) { onSpreadsheetsPermissionSuccess(); } else { @@ -270,7 +273,7 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv // Check Spreadsheets permission if (sendRequest.isSendSpreadsheets()) { Fragment fragment = CheckPermissionFragment.newInstance( - sendRequest.getAccount().name, SendToGoogleUtils.SPREADSHEET_SCOPE); + sendRequest.getAccount().name, SendToGoogleUtils.SPREADSHEETS_SCOPE); getSupportFragmentManager() .beginTransaction().add(fragment, CheckPermissionFragment.CHECK_PERMISSION_TAG).commit(); } else { diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/SendToGoogleUtils.java b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/SendToGoogleUtils.java index 8c75f3bb9..8d4a2ae7f 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/SendToGoogleUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/SendToGoogleUtils.java @@ -47,20 +47,14 @@ public class SendToGoogleUtils { private static final String TAG = SendToGoogleUtils.class.getSimpleName(); - // Request code to obtain Drive permission - public static final int DRIVE_PERMISSION_REQUEST_CODE = 1; public static final String DRIVE_SCOPE = DriveScopes.DRIVE; public static final int DRIVE_NOTIFICATION_ID = 1; - // Request code to obtain Fusion Tables permission - public static final int FUSION_TABLES_PERMISSION_REQUEST_CODE = 2; public static final String FUSION_TABLES_SCOPE = FusiontablesScopes.FUSIONTABLES; public static final int FUSION_TABLES_NOTIFICATION_ID = 2; - // Request code to obtain Spreadsheet permission - public static final int SPREADSHEET_PERMISSION_REQUEST_CODE = 3; - public static final String SPREADSHEET_SCOPE = "https://spreadsheets.google.com/feeds"; - public static final int SPREADSHEET_NOTIFICATION_ID = 3; + public static final String SPREADSHEETS_SCOPE = "https://spreadsheets.google.com/feeds"; + public static final int SPREADSHEETS_NOTIFICATION_ID = 3; private SendToGoogleUtils() {} diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/spreadsheets/SendSpreadsheetsAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/spreadsheets/SendSpreadsheetsAsyncTask.java index 4a3daeb11..ee16a4fff 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/spreadsheets/SendSpreadsheetsAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/spreadsheets/SendSpreadsheetsAsyncTask.java @@ -103,7 +103,7 @@ public class SendSpreadsheetsAsyncTask extends AbstractSendAsyncTask { Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); credential.setAccessToken( - SendToGoogleUtils.getToken(context, account.name, SendToGoogleUtils.SPREADSHEET_SCOPE)); + SendToGoogleUtils.getToken(context, account.name, SendToGoogleUtils.SPREADSHEETS_SCOPE)); spreadsheetService.setOAuth2Credentials(credential); Track track = myTracksProviderUtils.getTrack(trackId); @@ -141,14 +141,14 @@ public class SendSpreadsheetsAsyncTask extends AbstractSendAsyncTask { return true; } catch (UserRecoverableAuthException e) { SendToGoogleUtils.sendNotification( - context, account.name, e.getIntent(), SendToGoogleUtils.SPREADSHEET_NOTIFICATION_ID); + context, account.name, e.getIntent(), SendToGoogleUtils.SPREADSHEETS_NOTIFICATION_ID); return false; } catch (GoogleAuthException e) { Log.e(TAG, "GoogleaAuthException", e); return retryTask(); } catch (UserRecoverableAuthIOException e) { SendToGoogleUtils.sendNotification( - context, account.name, e.getIntent(), SendToGoogleUtils.SPREADSHEET_NOTIFICATION_ID); + context, account.name, e.getIntent(), SendToGoogleUtils.SPREADSHEETS_NOTIFICATION_ID); return false; } catch (IOException e) { Log.e(TAG, "IOException", e); diff --git a/MyTracks/src/com/google/android/apps/mytracks/settings/GoogleSettingsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/settings/GoogleSettingsActivity.java index 42da9b351..bb687d3d3 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/settings/GoogleSettingsActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/settings/GoogleSettingsActivity.java @@ -57,7 +57,7 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity { private static final String ACCOUNT_NAME_KEY = "accountName"; private static final int DIALOG_CONFIRM_SWITCH_ACCOUNT = 0; private static final int DIALOG_CONFIRM_DRIVE_SYNC_ON = 1; - + private static final int DRIVE_REQUEST_CODE = 0; private ListPreference googleAccountPreference; private CheckBoxPreference driveSyncPreference; @@ -122,7 +122,7 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { - case SendToGoogleUtils.DRIVE_PERMISSION_REQUEST_CODE: + case DRIVE_REQUEST_CODE: SendToGoogleUtils.cancelNotification(this, SendToGoogleUtils.DRIVE_NOTIFICATION_ID); if (resultCode == Activity.RESULT_OK) { onDrivePermissionSuccess(); @@ -195,7 +195,7 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity { onDrivePermissionSuccess(); } else { if (intent != null) { - startActivityForResult(intent, SendToGoogleUtils.DRIVE_PERMISSION_REQUEST_CODE); + startActivityForResult(intent, DRIVE_REQUEST_CODE); } else { onDrivePermissionFailure(); } diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java index 03ce8363e..2ec50a216 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java @@ -312,7 +312,7 @@ public class GoogleUtils { SpreadsheetService spreadsheetService = new SpreadsheetService(spreadsheetTitle); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); credential.setAccessToken(SendToGoogleUtils.getToken(activity.getApplicationContext(), - accountName, SendToGoogleUtils.SPREADSHEET_SCOPE)); + accountName, SendToGoogleUtils.SPREADSHEETS_SCOPE)); spreadsheetService.setOAuth2Credentials(credential); // Get work sheet.