Bug 1019735 - Hide the button toast if the user touches outside of it. r=lucasr

* * *
Bug 1019735 - (Part 2) Don't do unnecssary work on every touch
This commit is contained in:
Margaret Leibovic 2014-06-12 09:31:47 -07:00
parent c8b355cd23
commit 4aa844a8c1
2 changed files with 17 additions and 2 deletions

View File

@ -487,7 +487,7 @@ abstract public class BrowserApp extends GeckoApp
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT);
}
((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideTabsTouchListener());
((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideOnTouchListener());
((GeckoApp.MainLayout) mMainLayout).setMotionEventInterceptor(new MotionEventInterceptor() {
@Override
public boolean onInterceptMotionEvent(View view, MotionEvent event) {
@ -1985,11 +1985,20 @@ abstract public class BrowserApp extends GeckoApp
mBrowserSearch.setUserVisibleHint(false);
}
private class HideTabsTouchListener implements TouchEventInterceptor {
/**
* Hides certain UI elements (e.g. button toast, tabs tray) when the
* user touches the main layout.
*/
private class HideOnTouchListener implements TouchEventInterceptor {
private boolean mIsHidingTabs = false;
@Override
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
// Only try to hide the button toast if it's already inflated.
if (mToast != null) {
mToast.hide(false, ButtonToast.ReasonHidden.TOUCH_OUTSIDE);
}
// We need to account for scroll state for the touched view otherwise
// tapping on an "empty" part of the view will still be considered a
// valid touch event.

View File

@ -42,6 +42,7 @@ public class ButtonToast {
public enum ReasonHidden {
CLICKED,
TOUCH_OUTSIDE,
TIMEOUT,
REPLACED,
STARTUP
@ -129,6 +130,11 @@ public class ButtonToast {
}
public void hide(boolean immediate, ReasonHidden reason) {
// There's nothing to do if the view is already hidden.
if (mView.getVisibility() == View.GONE) {
return;
}
if (mCurrentToast != null && mCurrentToast.listener != null) {
mCurrentToast.listener.onToastHidden(reason);
}