Move experiment logic to Experiments.java. r=margaret
draft
Move experiment logic to Experiments.java. r=margaret
MozReview-Commit-ID: DO3f4nyjOZq
--- a/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPagerConfig.java
+++ b/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPagerConfig.java
@@ -2,61 +2,30 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.firstrun;
import android.content.Context;
import android.os.Bundle;
-import android.util.Log;
-import org.mozilla.gecko.GeckoSharedPrefs;
-import org.mozilla.gecko.R;
-import org.mozilla.gecko.Telemetry;
-import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.util.Experiments;
import java.util.LinkedList;
import java.util.List;
public class FirstrunPagerConfig {
public static final String LOGTAG = "FirstrunPagerConfig";
public static final String KEY_IMAGE = "imageRes";
public static final String KEY_TEXT = "textRes";
public static final String KEY_SUBTEXT = "subtextRes";
public static List<FirstrunPanelConfig> getDefault(Context context) {
- final List<FirstrunPanelConfig> panels = new LinkedList<>();
-
- if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING2_A)) {
- panels.add(new FirstrunPanelConfig(WelcomePanel.class.getName(), WelcomePanel.TITLE_RES));
- Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING2_A);
- GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING2_A);
- } else if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING2_B)) {
- panels.add(SimplePanelConfigs.urlbarPanelConfig);
- panels.add(SimplePanelConfigs.bookmarksPanelConfig);
- panels.add(SimplePanelConfigs.syncPanelConfig);
- panels.add(new FirstrunPanelConfig(SyncPanel.class.getName(), SyncPanel.TITLE_RES));
- Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING2_B);
- GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING2_B);
- } else if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING2_C)) {
- panels.add(SimplePanelConfigs.urlbarPanelConfig);
- panels.add(SimplePanelConfigs.bookmarksPanelConfig);
- panels.add(SimplePanelConfigs.dataPanelConfig);
- panels.add(SimplePanelConfigs.syncPanelConfig);
- panels.add(new FirstrunPanelConfig(SyncPanel.class.getName(), SyncPanel.TITLE_RES));
- Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING2_C);
- GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING2_C);
- } else {
- Log.d(LOGTAG, "Not in an experiment!");
- panels.add(new FirstrunPanelConfig(WelcomePanel.class.getName(), WelcomePanel.TITLE_RES));
- }
-
- return panels;
+ return Experiments.getPanels(context);
}
public static List<FirstrunPanelConfig> getRestricted() {
final List<FirstrunPanelConfig> panels = new LinkedList<>();
panels.add(new FirstrunPanelConfig(RestrictedWelcomePanel.class.getName(), RestrictedWelcomePanel.TITLE_RES));
return panels;
}
@@ -95,15 +64,10 @@ public class FirstrunPagerConfig {
return this.titleRes;
}
public Bundle getArgs() {
return args;
}
}
- protected static class SimplePanelConfigs {
- public static final FirstrunPanelConfig urlbarPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_panel_title_welcome, R.drawable.firstrun_urlbar, R.string.firstrun_urlbar_message, R.string.firstrun_urlbar_subtext);
- public static final FirstrunPanelConfig bookmarksPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_bookmarks_title, R.drawable.firstrun_bookmarks, R.string.firstrun_bookmarks_message, R.string.firstrun_bookmarks_subtext);
- public static final FirstrunPanelConfig syncPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_sync_title, R.drawable.firstrun_sync, R.string.firstrun_sync_message, R.string.firstrun_sync_subtext);
- public static final FirstrunPanelConfig dataPanelConfig = new FirstrunPanelConfig(DataPanel.class.getName(), R.string.firstrun_data_title, R.drawable.firstrun_data_off, R.string.firstrun_data_message, R.string.firstrun_data_subtext);
- }
+
}
--- a/mobile/android/base/java/org/mozilla/gecko/util/Experiments.java
+++ b/mobile/android/base/java/org/mozilla/gecko/util/Experiments.java
@@ -1,26 +1,45 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.util;
import android.content.Context;
+import android.util.Log;
import com.keepsafe.switchboard.SwitchBoard;
import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.GeckoSharedPrefs;
+import org.mozilla.gecko.R;
+import org.mozilla.gecko.Telemetry;
+import org.mozilla.gecko.TelemetryContract;
+import org.mozilla.gecko.firstrun.DataPanel;
+import org.mozilla.gecko.firstrun.FirstrunPagerConfig.FirstrunPanelConfig;
+import org.mozilla.gecko.firstrun.FirstrunPanel;
+import org.mozilla.gecko.firstrun.SyncPanel;
+import org.mozilla.gecko.firstrun.WelcomePanel;
+
+import java.util.LinkedList;
+import java.util.List;
/**
* This class should reflect the experiment names found in the Switchboard experiments config here:
* https://github.com/mozilla-services/switchboard-experiments
*/
public class Experiments {
+ private static final String LOGTAG = "GeckoExperiments";
+
// Display History and Bookmarks in 3-dot menu.
public static final String BOOKMARKS_HISTORY_MENU = "bookmark-history-menu";
+
+ // Show search mode (instead of home panels) when tapping on urlbar if there is a search term in the urlbar.
+ public static final String SEARCH_TERM = "search-term";
+
// Onboarding: "Features and Story"
public static final String ONBOARDING2_A = "onboarding2-a"; // Control: Single (blue) welcome screen
public static final String ONBOARDING2_B = "onboarding2-b"; // 4 static Feature slides
public static final String ONBOARDING2_C = "onboarding2-c"; // 4 static + 1 clickable (Data saving) Feature slides
public static final String PREF_ONBOARDING_VERSION = "onboarding_version";
/**
@@ -36,12 +55,45 @@ public class Experiments {
return Experiments.ONBOARDING2_B.equals(experiment);
} else if (SwitchBoard.isInBucket(context, 66, 100)) {
return Experiments.ONBOARDING2_C.equals(experiment);
}
}
return false;
}
- // Show search mode (instead of home panels) when tapping on urlbar if there is a search term in the urlbar.
- public static final String SEARCH_TERM = "search-term";
+ public static class SimplePanelConfigs {
+ public static final FirstrunPanelConfig urlbarPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_panel_title_welcome, R.drawable.firstrun_urlbar, R.string.firstrun_urlbar_message, R.string.firstrun_urlbar_subtext);
+ public static final FirstrunPanelConfig bookmarksPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_bookmarks_title, R.drawable.firstrun_bookmarks, R.string.firstrun_bookmarks_message, R.string.firstrun_bookmarks_subtext);
+ public static final FirstrunPanelConfig syncPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_sync_title, R.drawable.firstrun_sync, R.string.firstrun_sync_message, R.string.firstrun_sync_subtext);
+ public static final FirstrunPanelConfig dataPanelConfig = new FirstrunPanelConfig(DataPanel.class.getName(), R.string.firstrun_data_title, R.drawable.firstrun_data_off, R.string.firstrun_data_message, R.string.firstrun_data_subtext);
+ }
+
+ public static List<FirstrunPanelConfig> getPanels(Context context) {
+ List<FirstrunPanelConfig> panels = new LinkedList<>();
+ if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING2_A)) {
+ panels.add(new FirstrunPanelConfig(WelcomePanel.class.getName(), WelcomePanel.TITLE_RES));
+ Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING2_A);
+ GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING2_A);
+ } else if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING2_B)) {
+ panels.add(SimplePanelConfigs.urlbarPanelConfig);
+ panels.add(SimplePanelConfigs.bookmarksPanelConfig);
+ panels.add(SimplePanelConfigs.syncPanelConfig);
+ panels.add(new FirstrunPanelConfig(SyncPanel.class.getName(), SyncPanel.TITLE_RES));
+ Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING2_B);
+ GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING2_B);
+ } else if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING2_C)) {
+ panels.add(SimplePanelConfigs.urlbarPanelConfig);
+ panels.add(SimplePanelConfigs.bookmarksPanelConfig);
+ panels.add(SimplePanelConfigs.dataPanelConfig);
+ panels.add(SimplePanelConfigs.syncPanelConfig);
+ panels.add(new FirstrunPanelConfig(SyncPanel.class.getName(), SyncPanel.TITLE_RES));
+ Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING2_C);
+ GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING2_C);
+ } else {
+ Log.d(LOGTAG, "Not in an experiment!");
+ panels.add(new FirstrunPanelConfig(WelcomePanel.class.getName(), WelcomePanel.TITLE_RES));
+ }
+
+ return panels;
+ }
}