daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

Android: How to combine SurfaceLayout swipe event with OnTouchListener? #473

Open r0boto opened 7 years ago

r0boto commented 7 years ago

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

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:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:focusable="true"
              android:focusableInTouchMode="true"
              android:orientation="vertical"
              app:layout_behavior="@string/AUTO"
              app:layout_collapseParallaxMultiplier="1.0">
<com.daimajia.swipe.SwipeLayout
    android:id="@+id/swipe_layout"
    android:layout_width="match_parent" android:layout_height="180dp">
    <!-- Bottom View Start-->
    <LinearLayout
        android:background="#660011ff"
        android:id="@+id/bottom_wrapper"
        android:layout_width="160dp"
        android:weightSum="1"
        android:layout_height="match_parent">
        <!--What you want to show-->
    </LinearLayout>
    <!-- Bottom View End-->

    <!-- Surface View Start -->
    <LinearLayout
        android:id="@+id/top_wrapper"
        android:padding="10dp"
        android:background="#a71919"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!--What you want to show in SurfaceView-->
    </LinearLayout>
    <!-- Surface View End -->
</com.daimajia.swipe.SwipeLayout>
    </LinearLayout>