Bug 1266383 - Do not show HomeScreenPrompt if tab is not in foreground. r=ahunt
MozReview-Commit-ID: 1j7FKOfVt0X
--- a/mobile/android/base/java/org/mozilla/gecko/promotion/AddToHomeScreenPromotion.java
+++ b/mobile/android/base/java/org/mozilla/gecko/promotion/AddToHomeScreenPromotion.java
@@ -19,16 +19,17 @@ import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.BrowserAppDelegate;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.UrlAnnotations;
+import org.mozilla.gecko.tabs.TabsPanel;
import org.mozilla.gecko.util.Experiments;
import org.mozilla.gecko.util.ThreadUtils;
import java.lang.ref.WeakReference;
import ch.boye.httpclientandroidlib.util.TextUtils;
/**
@@ -48,37 +49,49 @@ public class AddToHomeScreenPromotion ex
private static final String LOGTAG = "GeckoPromoteShortcut";
private static final String EXPERIMENT_MINIMUM_TOTAL_VISITS = "minimumTotalVisits";
private static final String EXPERIMENT_LAST_VISIT_MINIMUM_AGE = "lastVisitMinimumAgeMs";
private static final String EXPERIMENT_LAST_VISIT_MAXIMUM_AGE = "lastVisitMaximumAgeMs";
private WeakReference<Activity> activityReference;
private boolean isEnabled;
+ private boolean isInForeground;
private int minimumVisits;
private int lastVisitMinimumAgeMs;
private int lastVisitMaximumAgeMs;
@Override
public void onCreate(BrowserApp browserApp, Bundle savedInstanceState) {
activityReference = new WeakReference<Activity>(browserApp);
+ isInForeground = true;
initializeExperiment(browserApp);
}
@Override
public void onResume(BrowserApp browserApp) {
Tabs.registerOnTabsChangedListener(this);
}
@Override
public void onPause(BrowserApp browserApp) {
Tabs.unregisterOnTabsChangedListener(this);
}
+ @Override
+ public void onTabsTrayShown(BrowserApp browserApp, TabsPanel tabsPanel) {
+ isInForeground = false;
+ }
+
+ @Override
+ public void onTabsTrayHidden(BrowserApp browserApp, TabsPanel tabsPanel) {
+ isInForeground = true;
+ }
+
private void initializeExperiment(Context context) {
if (!SwitchBoard.isInExperiment(context, Experiments.PROMOTE_ADD_TO_HOMESCREEN)) {
Log.v(LOGTAG, "Experiment not enabled");
// Experiment is not enabled. No need to try to read values.
return;
}
JSONObject values = SwitchBoard.getExperimentValuesFromJson(context, Experiments.PROMOTE_ADD_TO_HOMESCREEN);
@@ -112,24 +125,32 @@ public class AddToHomeScreenPromotion ex
return;
}
if (!Tabs.getInstance().isSelectedTab(tab)) {
// We only ever want to show this promotion for the current tab.
return;
}
- if (Tabs.TabEvents.LOADED == msg) {
- ThreadUtils.postToBackgroundThread(new Runnable() {
- @Override
- public void run() {
- maybeShowPromotionForUrl(tab.getURL(), tab.getTitle());
- }
- });
+ if (Tabs.TabEvents.LOADED != msg) {
+ return;
}
+
+ if (!isInForeground) {
+ // We only want to show this prompt if this tab is in the foreground and not on top
+ // of the tabs tray.
+ return;
+ }
+
+ ThreadUtils.postToBackgroundThread(new Runnable() {
+ @Override
+ public void run() {
+ maybeShowPromotionForUrl(tab.getURL(), tab.getTitle());
+ }
+ });
}
private void maybeShowPromotionForUrl(String url, String title) {
if (!isEnabled) {
return;
}
final Context context = activityReference.get();