当前位置:网站首页>Slide left from small window to large windowdispatchframelayout

Slide left from small window to large windowdispatchframelayout

2022-06-24 03:37:00 Zhaojian ZJ

DispatchFrameLayout

/* * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved. */

package com.qisi.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import lombok.Setter;

/** * 【 Typing flip chart 】 Content container , Set up dispatchTouchEvent monitor  * * @author zhaojian * @since 2022-06-15 */
public class DispatchFrameLayout extends FrameLayout {
    
    @Setter
    private OnTouchListener dispatchOnTouchListener;

    /** *  Constructors  * * @param context  Context  */
    public DispatchFrameLayout(@NonNull Context context) {
    
        super(context);
    }

    /** *  Constructors  * * @param context  Context  * @param attrs AttributeSet */
    public DispatchFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
    
        super(context, attrs);
    }

    /** *  Constructors  * * @param context  Context  * @param attrs attrs * @param defStyleAttr defStyleAttr */
    public DispatchFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
    
        if (dispatchOnTouchListener != null) {
    
            return dispatchOnTouchListener.onTouch(this, ev) || super.dispatchTouchEvent(ev);
        }
        return super.dispatchTouchEvent(ev);
    }
}


    @SuppressLint("ClickableViewAccessibility")
    private void showBigWhenRecyclerViewMove() {
    
        DispatchFrameLayout typingContent = findViewById(R.id.typing_content);
        OnTouchListener dispatchOnTouchListener = new OnTouchListener() {
    

            private boolean isFirstIntercept = false;

            private int dx; //  Record last dx Distance of 

            @Override
            public boolean onTouch(View v, MotionEvent event) {
    
                //  Only the expression window , To intercept events 
                if (event == null || isFirstIntercept || !isExpress() || rotateTransitionListener.isExpand()) {
    
                    return false; //  Don't deal with 
                }
                int action = event.getAction();
                if (action == MotionEvent.ACTION_DOWN) {
    
                    dx = (int) event.getX();
                } else if (action == MotionEvent.ACTION_MOVE) {
    
                    final int distance = 10;
                    isFirstIntercept = Math.abs(event.getX() - dx) > distance;
                } else {
    
                    LogUtil.logV(TAG, MSG_DO_NOTHING);
                }
                if (isFirstIntercept) {
    
                    clickLeftButton();
                }
                return isFirstIntercept;
            }
        };
        typingContent.setDispatchOnTouchListener(dispatchOnTouchListener);
    }

 Please add a picture description

原网站

版权声明
本文为[Zhaojian ZJ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206232322024367.html