diff --git a/astrid/src/com/todoroo/astrid/service/StartupService.java b/astrid/src/com/todoroo/astrid/service/StartupService.java index f42ee0d74..ca306f1f0 100644 --- a/astrid/src/com/todoroo/astrid/service/StartupService.java +++ b/astrid/src/com/todoroo/astrid/service/StartupService.java @@ -201,6 +201,8 @@ public class StartupService { final int finalLatestVersion = latestSetVersion; + abTests.externalInit(context); + abChooser.makeChoicesForAllTests(latestSetVersion == 0, taskService.getUserActivationStatus()); abTestInvoker.reportAcquisition(); diff --git a/astrid/src/com/todoroo/astrid/service/abtesting/ABTests.java b/astrid/src/com/todoroo/astrid/service/abtesting/ABTests.java index 87b12f99b..ed98d0f57 100644 --- a/astrid/src/com/todoroo/astrid/service/abtesting/ABTests.java +++ b/astrid/src/com/todoroo/astrid/service/abtesting/ABTests.java @@ -8,6 +8,11 @@ package com.todoroo.astrid.service.abtesting; import java.util.HashMap; import java.util.Set; +import android.accounts.Account; +import android.content.Context; + +import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager; + /** * Helper class to define options with their probabilities and descriptions * @author Sam Bosley @@ -20,6 +25,30 @@ public class ABTests { initialize(); } + /** + * Initialization for any tests that require a context or other logic + * to be initialized should go here. This method is called from the startup + * service before any test choices are made, so it is safe to add + * tests here. It's also ok if this method is a no-op sometimes. + * @param context + */ + public void externalInit(Context context) { + // The outer 'if' statement is to prevent one test from being added one time + // and the other from being added later if the accounts changed + if (ABChooser.readChoiceForTest(AB_NEW_LOGIN_NO_GOOGLE) == ABChooser.NO_OPTION + && ABChooser.readChoiceForTest(AB_NEW_LOGIN_YES_GOOGLE) == ABChooser.NO_OPTION) { + GoogleAccountManager am = new GoogleAccountManager(context); + Account[] accounts = am.getAccounts(); + if (accounts == null || accounts.length == 0) { + addTest(AB_NEW_LOGIN_NO_GOOGLE, new int[] { 1, 1 }, + new int[] { 1, 0 }, new String[] { "old-welcome", "new-welcome" }); //$NON-NLS-1$//$NON-NLS-2$ + } else { + addTest(AB_NEW_LOGIN_YES_GOOGLE, new int[] { 1, 1, 1 }, + new int[] { 1, 0, 0 }, new String[] { "old-welcome", "new-welcome", "new-quick-welcome" }); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + } + } + } + /** * Gets the integer array of weighted probabilities for an option key * @param key @@ -127,6 +156,10 @@ public class ABTests { public static final String AB_DEFAULT_EDIT_TAB = "android_default_edit_tab"; //$NON-NLS-1$ + public static final String AB_NEW_LOGIN_NO_GOOGLE = "android_new_login_n_google"; //$NON-NLS-1$ + + public static final String AB_NEW_LOGIN_YES_GOOGLE = "android_new_login_y_google"; //$NON-NLS-1$ + private void initialize() { addTest(AB_FEATURED_LISTS, new int[] { 1, 1 }, diff --git a/astrid/src/com/todoroo/astrid/welcome/tutorial/WelcomePagerAdapter.java b/astrid/src/com/todoroo/astrid/welcome/tutorial/WelcomePagerAdapter.java index 732b7b424..b008ac1d1 100644 --- a/astrid/src/com/todoroo/astrid/welcome/tutorial/WelcomePagerAdapter.java +++ b/astrid/src/com/todoroo/astrid/welcome/tutorial/WelcomePagerAdapter.java @@ -21,6 +21,8 @@ import com.timsu.astrid.R; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; +import com.todoroo.astrid.service.abtesting.ABChooser; +import com.todoroo.astrid.service.abtesting.ABTests; import com.viewpagerindicator.TitleProvider; public class WelcomePagerAdapter extends PagerAdapter implements TitleProvider @@ -59,7 +61,7 @@ public class WelcomePagerAdapter extends PagerAdapter implements TitleProvider R.layout.welcome_walkthrough_page, R.layout.welcome_walkthrough_page, R.layout.welcome_walkthrough_page, - R.layout.welcome_walkthrough_simple_login, + R.layout.welcome_walkthrough_login_page, }; private final Context context; @@ -77,6 +79,23 @@ public class WelcomePagerAdapter extends PagerAdapter implements TitleProvider body[body.length - 1] = R.string.welcome_body_7_return; } else { // Setup login page from AB tests + if (ABChooser.readChoiceForTest(ABTests.AB_NEW_LOGIN_YES_GOOGLE) != ABChooser.NO_OPTION) { + int choice = ABChooser.readChoiceForTest(ABTests.AB_NEW_LOGIN_YES_GOOGLE); + switch (choice) { + case 1: + layouts[layouts.length - 1] = R.layout.actfm_login_activity; + break; + case 2: + layouts[layouts.length - 1] = R.layout.welcome_walkthrough_simple_login; + break; + default: + break; + } + } else if (ABChooser.readChoiceForTest(ABTests.AB_NEW_LOGIN_NO_GOOGLE) != ABChooser.NO_OPTION) { + int choice = ABChooser.readChoiceForTest(ABTests.AB_NEW_LOGIN_NO_GOOGLE); + if (choice == 1) + layouts[layouts.length - 1] = R.layout.actfm_login_activity; + } } }