daimajia / daimajia/AndroidSwipeLayout

Android: How to combine SurfaceLayout swipe event with OnTouchListener?

Open
#473 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.3k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

I'm using this library **AndroidSwipeLayout** for displaying surface view:

I'm trying to display custom view layout above all screens using the Window manager. Problem is that is cannot combine **addSwipeListener** on swipe layout with **setOnTouchListener** on root view together to achieve the result like on the image below.

[![enter image description here][1]][1]

I tried to add listeners to the different layout, but the result is still same-> I can move if Y-axis but not use swipe on surface view or vice versa.

Question is: is possible to solve it together in some good solution or i cannot combine this together easily?

Thanks for any advice.

**ViewSetup:**

private void setUpResultView() {
try{
resultView = LayoutInflater.from(this).inflate(R.layout.result_layout_surface, null);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);

params.gravity = Gravity.TOP | Gravity.LEFT;
//params.flags = BIND_ABOVE_CLIENT | BIND_NOT_FOREGROUND;
params.x = 0;
params.y = 0;

SwipeLayout swipeLayout = (SwipeLayout)resultView.findViewById(R.id.swipe_layout);

//set show mode.
swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);

//add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary)
swipeLayout.addDrag(SwipeLayout.DragEdge.Left, resultView.findViewById(R.id.bottom_wrapper));

swipeLayout.addSwipeListener(swipeListener);

resultView.setOnTouchListener(onTouchListener);

windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.addView(resultView, params);

}
catch (Exception e) {
e.printStackTrace();
}
}

**Listeners**

SwipeLayout.SwipeListener swipeListener = new SwipeLayout.SwipeListener() {
@Override
public void onClose(SwipeLayout layout) {
Logger.d("onClose");
}

@Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
Logger.d("onUpdate");
}

@Override
public void onStartOpen(SwipeLayout layout) {
Logger.d("onStartOpen");
}

@Override
public void onOpen(SwipeLayout layout) {
Logger.d("onOpen");//when the BottomView totally show.
}

@Override
public void onStartClose(SwipeLayout layout) {
Logger.d("onStartClose");
}

@Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
Logger.d("onHandRelease");//when user's hand released.
}
};

View.OnTouchListener onTouchListener= new View.OnTouchListener() {
private int lastAction;
private int initialX;
private int initialY;
private float initialTouchX;
private float initialTouchY;

@Override
public boolean onTouch(View v, MotionEvent event) {
Logger.d(event.getAction());
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Logger.d("ACTION_DOWN");
return true;
case MotionEvent.ACTION_UP:
Logger.d("ACTION_UP");

return true;
case MotionEvent.ACTION_MOVE:
Logger.d("ACTION_MOVE");
return true;
}
return false;
}
};

**Layout:**















[1]: https://i.stack.imgur.com/JFACF.png

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.