Commit 13e602c1 authored by dfalcantara's avatar dfalcantara Committed by Commit bot

[Hera] Be smarter about dismissing the callout

The runnable can run after the Activity has already died,
so be extra careful about getting rid of it.

* Let the ToolbarPhone know when the Activity is destroyed
  when the ToolbarManager gets destroyed.

* Keep track of the Handler and the Runnable that call
  #dismiss(), canceling it when necessary.

* Only let the Runnable dismiss the PopupWindow when it
  still thinks it is showing.

BUG=582539,607391

Review-Url: https://codereview.chromium.org/1932623002
Cr-Commit-Position: refs/heads/master@{#390303}
parent f93523a0
......@@ -27,6 +27,9 @@ public class TabSwitcherCallout extends TextBubble {
private static final int TAB_SWITCHER_CALLOUT_DISMISS_MS = 10000;
private static final float Y_OVERLAP_PERCENTAGE = 0.33f;
private final Handler mHandler;
private final Runnable mDismissRunnable;
/**
* Show the TabSwitcherCallout, if necessary.
* @param context Context to draw resources from.
......@@ -39,15 +42,6 @@ public class TabSwitcherCallout extends TextBubble {
final TabSwitcherCallout callout = new TabSwitcherCallout(context);
callout.show(tabSwitcherButton);
// Dismiss the popup automatically after a delay.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
callout.dismiss();
}
}, TAB_SWITCHER_CALLOUT_DISMISS_MS);
return callout;
}
......@@ -85,5 +79,26 @@ public class TabSwitcherCallout extends TextBubble {
private TabSwitcherCallout(Context context) {
super(context, Y_OVERLAP_PERCENTAGE);
setAnimationStyle(R.style.TabSwitcherCalloutAnimation);
// Dismiss the popup automatically after a delay.
mDismissRunnable = new Runnable() {
@Override
public void run() {
if (isShowing()) dismiss();
}
};
mHandler = new Handler();
}
@Override
public void show(View anchorView) {
super.show(anchorView);
mHandler.postDelayed(mDismissRunnable, TAB_SWITCHER_CALLOUT_DISMISS_MS);
}
@Override
public void dismiss() {
super.dismiss();
mHandler.removeCallbacks(mDismissRunnable);
}
}
\ No newline at end of file
......@@ -320,6 +320,11 @@ abstract class ToolbarLayout extends FrameLayout implements Toolbar {
mFindInPageToolbarShowing = showing;
}
/**
* Cleans up any code as necessary.
*/
public void destroy() { }
/**
* Sets the FullscreenManager, which controls when the toolbar is shown.
*/
......
......@@ -723,6 +723,7 @@ public class ToolbarManager implements ToolbarTabController, UrlFocusChangeListe
Tab currentTab = mToolbarModel.getTab();
if (currentTab != null) currentTab.removeObserver(mTabObserver);
mFindToolbarObservers.clear();
mToolbar.destroy();
}
/**
......
......@@ -1535,6 +1535,11 @@ public class ToolbarPhone extends ToolbarLayout
}
}
@Override
public void destroy() {
dismissTabSwitcherCallout();
}
@Override
public void setOnTabSwitcherClickHandler(OnClickListener listener) {
mTabSwitcherListener = listener;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment