Bug 1359531 - Part 1 - Call GeckoApp's tab event handler from web apps/custom tabs, too. r?sebastian,walkingice
We want to move the activity switching code into the activity (i.e. GeckoApp) itself and run it from its onTabChanged handler in response to the appropriate events (at the moment that's only SELECTED), so we need to ensure that this will actually be called within custom tabs/web apps as well.
Additionally, there's no need to separately register the tab events listener from the CustomTabs/WebAppActivity as well if our parent class already does it for us.
MozReview-Commit-ID: 6PIq1KncDcA
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -80,18 +80,16 @@ public class CustomTabsActivity extends
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
bindNavigationCallback(toolbar);
actionBarPresenter = new ActionBarPresenter(actionBar, getActionBarTextColor());
actionBarPresenter.displayUrlOnly(intent.getDataString());
actionBarPresenter.setBackgroundColor(IntentUtil.getToolbarColor(intent), getWindow());
actionBarPresenter.setTextLongClickListener(new UrlCopyListener());
-
- Tabs.registerOnTabsChangedListener(this);
}
@Override
protected void onTabOpenFromIntent(Tab tab) {
super.onTabOpenFromIntent(tab);
final String host = getReferrerHost();
recordCustomTabUsage(host);
@@ -178,33 +176,29 @@ public class CustomTabsActivity extends
}
@Override
protected int getNewTabFlags() {
return Tabs.LOADURL_CUSTOMTAB | super.getNewTabFlags();
}
@Override
- public void onDestroy() {
- super.onDestroy();
- Tabs.unregisterOnTabsChangedListener(this);
- }
-
- @Override
public int getLayout() {
return R.layout.customtabs_activity;
}
@Override
public View getDoorhangerOverlay() {
return doorhangerOverlay;
}
@Override
public void onTabChanged(Tab tab, TabEvents msg, String data) {
+ super.onTabChanged(tab, msg, data);
+
if (!Tabs.getInstance().isSelectedTab(tab) ||
tab.getType() != Tab.TabType.CUSTOMTAB) {
return;
}
if (msg == TabEvents.START
|| msg == TabEvents.STOP
|| msg == TabEvents.ADDED
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -91,18 +91,16 @@ public class WebAppActivity extends Sing
final View customView = actionBar.getCustomView();
mUrlView = (TextView) customView.findViewById(R.id.webapps_action_bar_url);
EventDispatcher.getInstance().registerUiThreadListener(this,
"Website:AppEntered",
"Website:AppLeft",
null);
-
- Tabs.registerOnTabsChangedListener(this);
}
@Override
public View getDoorhangerOverlay() {
return doorhangerOverlay;
}
@Override
@@ -128,16 +126,18 @@ public class WebAppActivity extends Sing
case "Website:AppLeft":
getSupportActionBar().show();
break;
}
}
@Override
public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
+ super.onTabChanged(tab, msg, data);
+
if (tab == null || !Tabs.getInstance().isSelectedTab(tab) ||
tab.getType() != Tab.TabType.WEBAPP) {
return;
}
if (msg == TabEvents.LOCATION_CHANGE ||
msg == TabEvents.SELECTED) {
mUrlView.setText(tab.getURL());
@@ -153,17 +153,16 @@ public class WebAppActivity extends Sing
@Override
public void onDestroy() {
super.onDestroy();
EventDispatcher.getInstance().unregisterUiThreadListener(this,
"Website:AppEntered",
"Website:AppLeft",
null);
- Tabs.unregisterOnTabsChangedListener(this);
}
@Override
protected int getNewTabFlags() {
return Tabs.LOADURL_WEBAPP | super.getNewTabFlags();
}
@Override