Change some code style.

This commit is contained in:
youtaol
2012-07-12 12:59:08 +08:00
parent be3422cf59
commit a267708ab5
3 changed files with 63 additions and 35 deletions
@@ -62,9 +62,11 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.rotateAllActivities(); EndToEndTestUtils.rotateAllActivities();
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_list_empty_message))); assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.track_list_empty_message)));
// There is no track now. // There is no track now.
trackListView = EndToEndTestUtils.SOLO.getCurrentListViews(); trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
assertEquals(0, trackListView.get(0).getCount()); assertEquals(0, trackListView.get(0).getCount());
@@ -75,7 +77,8 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
EndToEndTestUtils.GPX.toUpperCase())); EndToEndTestUtils.GPX.toUpperCase()));
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.sd_card_save_error_no_track))); .getString(R.string.sd_card_save_error_no_track)));
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
} }
/** /**
@@ -91,7 +94,7 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
EndToEndTestUtils.SOLO.clickOnView(trackListView.get(0).getChildAt(0)); EndToEndTestUtils.SOLO.clickOnView(trackListView.get(0).getChildAt(0));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete), true);
EndToEndTestUtils EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
trackListView = EndToEndTestUtils.SOLO.getCurrentListViews(); trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
int trackNumberNew = trackListView.get(0).getCount(); int trackNumberNew = trackListView.get(0).getCount();
@@ -192,24 +192,24 @@ public class EndToEndTestUtils {
setIsEmulator(); setIsEmulator();
EndToEndTestUtils.instrumentation = instrumentation; EndToEndTestUtils.instrumentation = instrumentation;
EndToEndTestUtils.activityMytracks = activityMyTracks; EndToEndTestUtils.activityMytracks = activityMyTracks;
EndToEndTestUtils.SOLO = new Solo(EndToEndTestUtils.instrumentation, SOLO = new Solo(EndToEndTestUtils.instrumentation,
EndToEndTestUtils.activityMytracks); EndToEndTestUtils.activityMytracks);
// Check if open MyTracks first time after install. If so, there would be a // Check if open MyTracks first time after install. If so, there would be a
// welcome view with accept buttons. And makes sure only check once. // welcome view with accept buttons. And makes sure only check once.
if (!EndToEndTestUtils.isCheckedFirstLaunch) { if (!isCheckedFirstLaunch) {
if ((EndToEndTestUtils.getButtonOnScreen(EndToEndTestUtils.activityMytracks if ((getButtonOnScreen(EndToEndTestUtils.activityMytracks
.getString(R.string.eula_accept), false, false) != null)) { .getString(R.string.eula_accept), false, false) != null)) {
EndToEndTestUtils.verifyFirstLaunch(); verifyFirstLaunch();
} else if (EndToEndTestUtils.SOLO.waitForText( } else if (SOLO.waitForText(
// After reset setting, welcome page will show again. // After reset setting, welcome page will show again.
activityMytracks.getString(R.string.welcome_title), 0, 500)) { activityMytracks.getString(R.string.welcome_title), 0, 500)) {
resetPreferredUnits(); resetPreferredUnits();
} }
checkLanguage(); checkLanguage();
EndToEndTestUtils.isCheckedFirstLaunch = true; isCheckedFirstLaunch = true;
EndToEndTestUtils.setHasActionBar(); setHasActionBar();
EndToEndTestUtils.resetAllSettings(activityMyTracks, false); resetAllSettings(activityMyTracks, false);
} else if (EndToEndTestUtils.SOLO.waitForText( } else if (SOLO.waitForText(
// After reset setting, welcome page will show again. // After reset setting, welcome page will show again.
activityMytracks.getString(R.string.welcome_title), 0, 500)) { activityMytracks.getString(R.string.welcome_title), 0, 500)) {
resetPreferredUnits(); resetPreferredUnits();
@@ -266,7 +266,7 @@ public class EndToEndTestUtils {
*/ */
static void createSimpleTrack(int numberOfGpsData) { static void createSimpleTrack(int numberOfGpsData) {
startRecording(); startRecording();
EndToEndTestUtils.sendGps(numberOfGpsData); sendGps(numberOfGpsData);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
stopRecording(true); stopRecording(true);
} }
@@ -301,11 +301,11 @@ public class EndToEndTestUtils {
* activity * activity
*/ */
static void createTrackIfEmpty(int gpsNumber, boolean showTrackList) { static void createTrackIfEmpty(int gpsNumber, boolean showTrackList) {
if (EndToEndTestUtils.isTrackListEmpty(!showTrackList)) { if (isTrackListEmpty(!showTrackList)) {
// Create a simple track. // Create a simple track.
EndToEndTestUtils.createSimpleTrack(gpsNumber); createSimpleTrack(gpsNumber);
if (showTrackList) { if (showTrackList) {
EndToEndTestUtils.SOLO.goBack(); SOLO.goBack();
} }
} }
} }
@@ -374,17 +374,17 @@ public class EndToEndTestUtils {
SOLO.clickOnText(activityMytracks.getString(R.string.menu_stop_recording)); SOLO.clickOnText(activityMytracks.getString(R.string.menu_stop_recording));
} }
if (isSave) { if (isSave) {
EndToEndTestUtils.SOLO.waitForText(activityMytracks.getString(R.string.generic_save), 1, 5000); SOLO.waitForText(activityMytracks.getString(R.string.generic_save), 1, 5000);
// Make every track name is unique to make sure every check can be // Make every track name is unique to make sure every check can be
// trusted. // trusted.
EndToEndTestUtils.trackName = EndToEndTestUtils.TRACK_NAME_PREFIX trackName = TRACK_NAME_PREFIX
+ System.currentTimeMillis(); + System.currentTimeMillis();
SOLO.sendKey(KeyEvent.KEYCODE_DEL); SOLO.sendKey(KeyEvent.KEYCODE_DEL);
SOLO.enterText(0, trackName); SOLO.enterText(0, trackName);
SOLO.enterText(1, DEFAULTACTIVITY); SOLO.enterText(1, DEFAULTACTIVITY);
if(!EndToEndTestUtils.isEmulator) { if(!isEmulator) {
// Close soft keyboard. // Close soft keyboard.
EndToEndTestUtils.SOLO.goBack(); SOLO.goBack();
} }
SOLO.clickLongOnText(activityMytracks.getString(R.string.generic_save)); SOLO.clickLongOnText(activityMytracks.getString(R.string.generic_save));
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
@@ -494,7 +494,7 @@ public class EndToEndTestUtils {
* Rotates the current activity. * Rotates the current activity.
*/ */
static void rotateCurrentActivity() { static void rotateCurrentActivity() {
EndToEndTestUtils.rotateActivity(SOLO.getCurrentActivity()); rotateActivity(SOLO.getCurrentActivity());
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
} }
@@ -504,7 +504,7 @@ public class EndToEndTestUtils {
static void rotateAllActivities() { static void rotateAllActivities() {
ArrayList<Activity> allActivities = SOLO.getAllOpenedActivities(); ArrayList<Activity> allActivities = SOLO.getAllOpenedActivities();
for (Activity activity : allActivities) { for (Activity activity : allActivities) {
EndToEndTestUtils.rotateActivity(activity); rotateActivity(activity);
} }
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
@@ -588,7 +588,7 @@ public class EndToEndTestUtils {
* @return the text view, null means can not find it * @return the text view, null means can not find it
*/ */
static TextView findTextView(String findText, View parent) { static TextView findTextView(String findText, View parent) {
ArrayList<TextView> textViews = EndToEndTestUtils.SOLO.getCurrentTextViews(parent); ArrayList<TextView> textViews = SOLO.getCurrentTextViews(parent);
for (TextView textView : textViews) { for (TextView textView : textViews) {
String text = (String) textView.getText(); String text = (String) textView.getText();
if (textView.isShown() && text.endsWith(findText)) { if (textView.isShown() && text.endsWith(findText)) {
@@ -604,7 +604,7 @@ public class EndToEndTestUtils {
* @return the ChartView or null if not find * @return the ChartView or null if not find
*/ */
static ChartView getChartView() { static ChartView getChartView() {
ArrayList<View> views = EndToEndTestUtils.SOLO.getViews(); ArrayList<View> views = SOLO.getViews();
for (View view : views) { for (View view : views) {
if (view instanceof ChartView) { if (view instanceof ChartView) {
return (ChartView) view; return (ChartView) view;
@@ -620,13 +620,13 @@ public class EndToEndTestUtils {
* @param keepInSettingList whether keep in setting list or not * @param keepInSettingList whether keep in setting list or not
*/ */
public static void resetAllSettings(Activity activityMyTracks, boolean keepInSettingList) { 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.waitForText(activityMyTracks.getString(R.string.settings_reset));
SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset)); SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset));
getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true); getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
if (!keepInSettingList) { if (!keepInSettingList) {
EndToEndTestUtils.SOLO.goBack(); SOLO.goBack();
} }
} }
@@ -62,17 +62,20 @@ import java.util.Locale;
* @author Youtao Liu * @author Youtao Liu
*/ */
public class GoogleUtils { public class GoogleUtils {
private static Account account;
public static final String LOG_TAG = "MyTracksTest"; public static final String LOG_TAG = "MyTracksTest";
public static final String DOCUMENT_NAME_PREFIX = "My Tracks"; public static final String DOCUMENT_NAME_PREFIX = "My Tracks";
public static final String SPREADSHEET_NAME = DOCUMENT_NAME_PREFIX + "-" + EndToEndTestUtils.DEFAULTACTIVITY; 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) { private static Account getAccount(Context context) {
return account == null ? account = AccountManager.get(context).getAccountsByType( return AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE)[0];
Constants.ACCOUNT_TYPE)[0] : account;
} }
/** /**
* Gets Google maps of a user. * Gets Google maps of a user.
* *
@@ -81,7 +84,6 @@ public class GoogleUtils {
* @return true means set successfully * @return true means set successfully
*/ */
private static ArrayList<MapsMapMetadata> getMaps(Context context, MapsClient mapsClient) { private static ArrayList<MapsMapMetadata> getMaps(Context context, MapsClient mapsClient) {
// Reset the per request states
String authToken = null; String authToken = null;
ArrayList<String> mapIds = new ArrayList<String>(); ArrayList<String> mapIds = new ArrayList<String>();
ArrayList<MapsMapMetadata> mapData = new ArrayList<MapsMapMetadata>(); ArrayList<MapsMapMetadata> mapData = new ArrayList<MapsMapMetadata>();
@@ -176,7 +178,7 @@ public class GoogleUtils {
* @param activity to get context * @param activity to get context
* @return the entry of the document, null means can not find the spreadsheet. * @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(); Context context = activity.getApplicationContext();
DocumentsClient documentsClient = new DocumentsClient( DocumentsClient documentsClient = new DocumentsClient(
GDataClientFactory.getGDataClient(context), GDataClientFactory.getGDataClient(context),
@@ -214,8 +216,8 @@ public class GoogleUtils {
* @param isDelete whether delete the information of this track in the document * @param isDelete whether delete the information of this track in the document
* @return true means find the track name in the spreadsheet * @return true means find the track name in the spreadsheet
*/ */
public static boolean searchTrackTitleInSpreadsheet(String title, Activity activity, String spreadsheetTitle, boolean isDelete) { private static boolean searchTrackTitleInSpreadsheet(String title, Activity activity, String spreadsheetTitle, boolean isDelete) {
String spreadsheetId = searchSepeadsheetByTitle(spreadsheetTitle, activity).getId().replace(SendDocsUtils.SPREADSHEET_ID_PREFIX, ""); String spreadsheetId = searchSpreadsheetByTitle(spreadsheetTitle, activity).getId().replace(SendDocsUtils.SPREADSHEET_ID_PREFIX, "");
if(spreadsheetId == null) { if(spreadsheetId == null) {
Log.d(LOG_TAG, "Unable to find the spreadsheet -- " + spreadsheetTitle); Log.d(LOG_TAG, "Unable to find the spreadsheet -- " + spreadsheetTitle);
return false; return false;
@@ -249,6 +251,28 @@ public class GoogleUtils {
} }
return false; 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. * 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 title the title of a track to drop
* @param activity to get context * @param activity to get context
* @return the result of drop
*/ */
public static boolean dropFusionTables(String title, Activity activity) { public static boolean dropFusionTables(String title, Activity activity) {
Context context = activity.getApplicationContext(); Context context = activity.getApplicationContext();