This source file includes following definitions.
- setOnAppMenuShownListener
- showAppMenu
- isAppMenuShowing
- onEnterKeyPress
- onDown
- onSingleTapUp
- onScroll
- onTouch
package org.chromium.chrome.browser.appmenu;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import org.chromium.chrome.browser.UmaBridge;
public class AppMenuButtonHelper extends SimpleOnGestureListener implements OnTouchListener {
private final View mMenuButton;
private final AppMenuHandler mMenuHandler;
private final GestureDetector mAppMenuGestureDetector;
private boolean mSeenFirstScrollEvent;
private Runnable mOnAppMenuShownListener;
public AppMenuButtonHelper(View menuButton, AppMenuHandler menuHandler) {
mMenuButton = menuButton;
mMenuHandler = menuHandler;
mAppMenuGestureDetector = new GestureDetector(menuButton.getContext(), this);
mAppMenuGestureDetector.setIsLongpressEnabled(false);
}
public void setOnAppMenuShownListener(Runnable onAppMenuShownListener) {
mOnAppMenuShownListener = onAppMenuShownListener;
}
private boolean showAppMenu(boolean startDragging) {
if (!mMenuHandler.isAppMenuShowing() &&
mMenuHandler.showAppMenu(mMenuButton, false, startDragging)) {
UmaBridge.usingMenu(false, startDragging);
if (mOnAppMenuShownListener != null) {
mOnAppMenuShownListener.run();
}
return true;
}
return false;
}
public boolean isAppMenuShowing() {
return mMenuHandler.isAppMenuShowing();
}
public boolean onEnterKeyPress() {
return showAppMenu(false);
}
@Override
public boolean onDown(MotionEvent e) {
mSeenFirstScrollEvent = false;
mMenuButton.setPressed(true);
return true;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return showAppMenu(false);
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (mSeenFirstScrollEvent) return false;
mSeenFirstScrollEvent = true;
return -distanceY >= Math.abs(distanceX) && showAppMenu(true);
}
@Override
public boolean onTouch(View view, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_CANCEL ||
event.getActionMasked() == MotionEvent.ACTION_UP) {
mMenuButton.setPressed(false);
}
boolean isTouchEventConsumed = mAppMenuGestureDetector.onTouchEvent(event);
AppMenuDragHelper dragHelper = mMenuHandler.getAppMenuDragHelper();
if (dragHelper != null && !isTouchEventConsumed) {
isTouchEventConsumed |= dragHelper.handleDragging(event);
}
return isTouchEventConsumed;
}