我得手机分为两部分:整个屏幕的上部分是SurfaceView视频,下部分为按钮部分。现在需求是这样:
按钮部分屏蔽触摸事件,只能响应电击事件;视频部分不做限制。现在的问题是这样:按钮部分现在也响应触摸事件,怎么屏蔽掉触摸事件呢(我想让下半部分整体屏蔽掉触摸事件)。
请教大神怎么做呀?
public boolean onTouchEvent(MotionEvent event) {
if (mIsLocked) {
// locked, only handle show/hide & ignore all actions
if (event.getAction() == MotionEvent.ACTION_UP) {
if (!mShowing) {
showOverlay();
} else {
hideOverlay(true);
}
}
return false;
}
float y = event.getY();
if(y < height_flag){
DisplayMetrics screen = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(screen);
if (mSurfaceYDisplayRange == 0)
mSurfaceYDisplayRange = Math.min(screen.widthPixels, screen.heightPixels);
float y_changed = event.getRawY() - mTouchY;
float x_changed = event.getRawX() - mTouchX;
// coef is the gradient's move to determine a neutral zone
float coef = Math.abs (y_changed / x_changed);
float xgesturesize = ((x_changed / screen.xdpi) * 2.54f);
/* Offset for Mouse Events */
int[] offset = new int[2];
mSurface.getLocationOnScreen(offset);
int xTouch = Math.round((event.getRawX() - offset[0]) * mVideoWidth / mSurface.getWidth());
int yTouch = Math.round((event.getRawY() - offset[1]) * mVideoHeight / mSurface.getHeight());
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Audio
mTouchY = event.getRawY();
mVol = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mTouchAction = TOUCH_NONE;
// Seek
mTouchX = event.getRawX();
// Mouse events for the core
LibVLC.sendMouseEvent(MotionEvent.ACTION_DOWN, 0, xTouch, yTouch);
break;
case MotionEvent.ACTION_MOVE:
// Mouse events for the core
LibVLC.sendMouseEvent(MotionEvent.ACTION_MOVE, 0, xTouch, yTouch);
// No volume/brightness action if coef < 2 or a secondary display is connected
//TODO : Volume action when a secondary display is connected
if (coef > 2 && mPresentation == null) {
// Volume (Up or Down - Right side)
if (!mEnableBrightnessGesture || mTouchX > (screen.widthPixels / 2)){
doVolumeTouch(y_changed);
}
// Brightness (Up or Down - Left side)
if (mEnableBrightnessGesture && mTouchX < (screen.widthPixels / 2)){
doBrightnessTouch(y_changed);
}
// Extend the overlay for a little while, so that it doesn't
// disappear on the user if more adjustment is needed. This
// is because on devices with soft navigation (e.g. Galaxy
// Nexus), gestures can't be made without activating the UI.
if(AndroidDevices.hasNavBar())
showOverlay();
}
// Seek (Right or Left move)
doSeekTouch(coef, xgesturesize, false);
break;
case MotionEvent.ACTION_UP:
// Mouse events for the core
LibVLC.sendMouseEvent(MotionEvent.ACTION_UP, 0, xTouch, yTouch);
// Audio or Brightness
if ( mTouchAction == TOUCH_NONE) {
if (!mShowing) {
showOverlay();
} else {
hideOverlay(true);
}
}
// Seek
doSeekTouch(coef, xgesturesize, true);
break;
}
return mTouchAction != TOUCH_NONE;
}
else{
return false;
}
}