Bug 777026: Use a touch delegate on Tabs button to overcome overlapping on menu button. [r=mfinkle]

This commit is contained in:
Sriram Ramasubramanian 2012-08-20 00:45:37 -04:00
Родитель 97b3aac240
Коммит db7145cb00
1 изменённых файлов: 40 добавлений и 0 удалений

Просмотреть файл

@ -10,6 +10,7 @@ import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.SystemClock;
@ -18,6 +19,8 @@ import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MotionEvent;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
@ -224,6 +227,19 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
mActivity.openOptionsMenu();
}
});
// Set a touch delegate to Tabs button, so the touch events on its tail
// are passed to the menu button.
mLayout.post(new Runnable() {
@Override
public void run() {
int height = mTabs.getHeight();
int width = mTabs.getWidth();
int tail = (width - height) / 2;
Rect bounds = new Rect(width - tail, 0, width, height);
mTabs.setTouchDelegate(new TailTouchDelegate(bounds, mMenu));
}
});
}
if (Build.VERSION.SDK_INT >= 11) {
@ -601,4 +617,28 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
mPanel.addView(view);
}
}
private class TailTouchDelegate extends TouchDelegate {
public TailTouchDelegate(Rect bounds, View delegateView) {
super(bounds, delegateView);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Android bug 36445: Touch Delegation not reset on ACTION_DOWN.
if (!super.onTouchEvent(event)) {
MotionEvent cancelEvent = MotionEvent.obtain(event);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(cancelEvent);
return false;
} else {
return true;
}
default:
return super.onTouchEvent(event);
}
}
}
}