From a267708ab5138fd8184ccc29f51305e9adb5b0dd Mon Sep 17 00:00:00 2001 From: youtaol Date: Thu, 12 Jul 2012 12:59:08 +0800 Subject: [PATCH] Change some code style. --- .../mytracks/endtoendtest/DeleteTest.java | 11 +++-- .../endtoendtest/EndToEndTestUtils.java | 46 +++++++++---------- .../mytracks/endtoendtest/GoogleUtils.java | 41 +++++++++++++---- 3 files changed, 63 insertions(+), 35 deletions(-) diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/DeleteTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/DeleteTest.java index e26a2cd8d..4943ec287 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/DeleteTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/DeleteTest.java @@ -62,9 +62,11 @@ public class DeleteTest extends ActivityInstrumentationTestCase2 allActivities = SOLO.getAllOpenedActivities(); for (Activity activity : allActivities) { - EndToEndTestUtils.rotateActivity(activity); + rotateActivity(activity); } instrumentation.waitForIdleSync(); @@ -588,7 +588,7 @@ public class EndToEndTestUtils { * @return the text view, null means can not find it */ static TextView findTextView(String findText, View parent) { - ArrayList textViews = EndToEndTestUtils.SOLO.getCurrentTextViews(parent); + ArrayList textViews = SOLO.getCurrentTextViews(parent); for (TextView textView : textViews) { String text = (String) textView.getText(); if (textView.isShown() && text.endsWith(findText)) { @@ -604,7 +604,7 @@ public class EndToEndTestUtils { * @return the ChartView or null if not find */ static ChartView getChartView() { - ArrayList views = EndToEndTestUtils.SOLO.getViews(); + ArrayList views = SOLO.getViews(); for (View view : views) { if (view instanceof ChartView) { return (ChartView) view; @@ -620,13 +620,13 @@ public class EndToEndTestUtils { * @param keepInSettingList whether keep in setting list or not */ public static void resetAllSettings(Activity activityMyTracks, boolean keepInSettingList) { - EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); + findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); SOLO.waitForText(activityMyTracks.getString(R.string.settings_reset)); SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset)); getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true); instrumentation.waitForIdleSync(); if (!keepInSettingList) { - EndToEndTestUtils.SOLO.goBack(); + SOLO.goBack(); } } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java index 61fbe80bc..8ba9f0631 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java @@ -62,17 +62,20 @@ import java.util.Locale; * @author Youtao Liu */ public class GoogleUtils { - private static Account account; public static final String LOG_TAG = "MyTracksTest"; public static final String DOCUMENT_NAME_PREFIX = "My Tracks"; public static final String SPREADSHEET_NAME = DOCUMENT_NAME_PREFIX + "-" + EndToEndTestUtils.DEFAULTACTIVITY; + /** + * Gets the account to access Google Services. + * + * @param context context used to get account + * @return the first account which is bound with current device + */ private static Account getAccount(Context context) { - return account == null ? account = AccountManager.get(context).getAccountsByType( - Constants.ACCOUNT_TYPE)[0] : account; + return AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE)[0]; } - /** * Gets Google maps of a user. * @@ -81,7 +84,6 @@ public class GoogleUtils { * @return true means set successfully */ private static ArrayList getMaps(Context context, MapsClient mapsClient) { - // Reset the per request states String authToken = null; ArrayList mapIds = new ArrayList(); ArrayList mapData = new ArrayList(); @@ -176,7 +178,7 @@ public class GoogleUtils { * @param activity to get context * @return the entry of the document, null means can not find the spreadsheet. */ - private static Entry searchSepeadsheetByTitle(String title, Activity activity) { + private static Entry searchSpreadsheetByTitle(String title, Activity activity) { Context context = activity.getApplicationContext(); DocumentsClient documentsClient = new DocumentsClient( GDataClientFactory.getGDataClient(context), @@ -214,8 +216,8 @@ public class GoogleUtils { * @param isDelete whether delete the information of this track in the document * @return true means find the track name in the spreadsheet */ - public static boolean searchTrackTitleInSpreadsheet(String title, Activity activity, String spreadsheetTitle, boolean isDelete) { - String spreadsheetId = searchSepeadsheetByTitle(spreadsheetTitle, activity).getId().replace(SendDocsUtils.SPREADSHEET_ID_PREFIX, ""); + private static boolean searchTrackTitleInSpreadsheet(String title, Activity activity, String spreadsheetTitle, boolean isDelete) { + String spreadsheetId = searchSpreadsheetByTitle(spreadsheetTitle, activity).getId().replace(SendDocsUtils.SPREADSHEET_ID_PREFIX, ""); if(spreadsheetId == null) { Log.d(LOG_TAG, "Unable to find the spreadsheet -- " + spreadsheetTitle); return false; @@ -249,6 +251,28 @@ public class GoogleUtils { } return false; } + + /** + * Searches a track in spreadsheet. + * + * @param title the track name to search + * @param activity to get context + * @return true means find the track name in the spreadsheet + */ + public static boolean searchTrackInSpreadSheet(String title, Activity activity) { + return searchTrackTitleInSpreadsheet(title, activity, GoogleUtils.SPREADSHEET_NAME, false); + } + + /** + * Searches and deletes a track in spreadsheet. + * + * @param title the track name to search + * @param activity to get context + * @return true means find and delete successfully + */ + public static boolean deleteTrackInSpreadSheet(String title, Activity activity) { + return searchTrackTitleInSpreadsheet(title, activity, GoogleUtils.SPREADSHEET_NAME, true); + } /** * Searches a fusion table in user's Google tables. @@ -276,6 +300,7 @@ public class GoogleUtils { * * @param title the title of a track to drop * @param activity to get context + * @return the result of drop */ public static boolean dropFusionTables(String title, Activity activity) { Context context = activity.getApplicationContext();