From ffb049db0bd4df178efdda3ba52c8f10519c57dd Mon Sep 17 00:00:00 2001 From: imndx Date: Fri, 26 Apr 2019 23:22:25 +0800 Subject: [PATCH] fix viewpager onInterceptTouchEvent issue --- .../wildfire/chat/app/main/MainActivity.java | 3 +- .../conversation/ConversationInputPanel.java | 4 +- .../ext/core/ConversationExtension.java | 11 +++--- .../chat/kit/preview/MMPreviewActivity.java | 10 +++-- .../chat/kit/widget/ViewPagerFixed.java | 29 ++++++++++++++ .../java/com/lqr/emoji/EmotionLayout.java | 2 +- .../java/com/lqr/emoji/ViewPagerFixed.java | 38 +++++++++++++++++++ 7 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 chat/src/main/java/cn/wildfire/chat/kit/widget/ViewPagerFixed.java create mode 100755 emojilibrary/src/main/java/com/lqr/emoji/ViewPagerFixed.java diff --git a/chat/src/main/java/cn/wildfire/chat/app/main/MainActivity.java b/chat/src/main/java/cn/wildfire/chat/app/main/MainActivity.java index 935c2d529..0042836b6 100644 --- a/chat/src/main/java/cn/wildfire/chat/app/main/MainActivity.java +++ b/chat/src/main/java/cn/wildfire/chat/app/main/MainActivity.java @@ -46,6 +46,7 @@ import cn.wildfire.chat.kit.user.ChangeMyNameActivity; import cn.wildfire.chat.kit.user.UserInfoActivity; import cn.wildfire.chat.kit.user.UserViewModel; +import cn.wildfire.chat.kit.widget.ViewPagerFixed; import cn.wildfirechat.chat.R; import cn.wildfirechat.model.Conversation; import cn.wildfirechat.model.UserInfo; @@ -58,7 +59,7 @@ public class MainActivity extends WfcBaseActivity implements ViewPager.OnPageCha @Bind(R.id.bottomNavigationView) BottomNavigationView bottomNavigationView; @Bind(R.id.vpContent) - ViewPager mVpContent; + ViewPagerFixed mVpContent; private QBadgeView unreadMessageUnreadBadgeView; private QBadgeView unreadFriendRequestBadgeView; diff --git a/chat/src/main/java/cn/wildfire/chat/kit/conversation/ConversationInputPanel.java b/chat/src/main/java/cn/wildfire/chat/kit/conversation/ConversationInputPanel.java index 193499833..57b8aa266 100644 --- a/chat/src/main/java/cn/wildfire/chat/kit/conversation/ConversationInputPanel.java +++ b/chat/src/main/java/cn/wildfire/chat/kit/conversation/ConversationInputPanel.java @@ -23,7 +23,6 @@ import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.ViewModelProviders; -import androidx.viewpager.widget.ViewPager; import com.lqr.emoji.EmotionLayout; import com.lqr.emoji.IEmotionExtClickListener; @@ -44,6 +43,7 @@ import cn.wildfire.chat.kit.group.GroupViewModel; import cn.wildfire.chat.kit.widget.InputAwareLayout; import cn.wildfire.chat.kit.widget.KeyboardHeightFrameLayout; +import cn.wildfire.chat.kit.widget.ViewPagerFixed; import cn.wildfirechat.chat.R; import cn.wildfirechat.message.TextMessageContent; import cn.wildfirechat.message.TypingMessageContent; @@ -77,7 +77,7 @@ public class ConversationInputPanel extends FrameLayout implements IEmotionSelec @Bind(R.id.inputPanelFrameLayout) FrameLayout inputContainerFrameLayout; @Bind(R.id.conversationExtViewPager) - ViewPager extViewPager; + ViewPagerFixed extViewPager; ConversationExtension extension; private Conversation conversation; diff --git a/chat/src/main/java/cn/wildfire/chat/kit/conversation/ext/core/ConversationExtension.java b/chat/src/main/java/cn/wildfire/chat/kit/conversation/ext/core/ConversationExtension.java index e52ba64ab..8dfa66c54 100644 --- a/chat/src/main/java/cn/wildfire/chat/kit/conversation/ext/core/ConversationExtension.java +++ b/chat/src/main/java/cn/wildfire/chat/kit/conversation/ext/core/ConversationExtension.java @@ -3,6 +3,8 @@ import android.content.Intent; import android.widget.FrameLayout; +import androidx.fragment.app.FragmentActivity; + import com.afollestad.materialdialogs.MaterialDialog; import java.lang.reflect.InvocationTargetException; @@ -10,17 +12,16 @@ import java.util.ArrayList; import java.util.List; -import androidx.fragment.app.FragmentActivity; -import androidx.viewpager.widget.ViewPager; import cn.wildfire.chat.kit.annotation.ExtContextMenuItem; import cn.wildfire.chat.kit.conversation.ConversationViewModel; +import cn.wildfire.chat.kit.widget.ViewPagerFixed; import cn.wildfirechat.model.Conversation; public class ConversationExtension { private FragmentActivity activity; private Conversation conversation; private FrameLayout containerLayout; - private ViewPager extViewPager; + private ViewPagerFixed extViewPager; private List exts; private boolean hideOnScroll = true; @@ -30,7 +31,7 @@ public class ConversationExtension { * @param inputContainerLayout 包含整个输入区域的framelayout * @param extViewPager 用于展示{@link ConversationExtPageView}, 每个ConversationExtPageView包含8个{@link ConversationExt} */ - public ConversationExtension(FragmentActivity activity, FrameLayout inputContainerLayout, ViewPager extViewPager) { + public ConversationExtension(FragmentActivity activity, FrameLayout inputContainerLayout, ViewPagerFixed extViewPager) { this.activity = activity; this.containerLayout = inputContainerLayout; this.extViewPager = extViewPager; @@ -84,7 +85,7 @@ public void bind(ConversationViewModel conversationViewModel, Conversation conve } } - private void setupExtViewPager(ViewPager viewPager) { + private void setupExtViewPager(ViewPagerFixed viewPager) { exts = ConversationExtManager.getInstance().getConversationExts(conversation); if (exts.isEmpty()) { return; diff --git a/chat/src/main/java/cn/wildfire/chat/kit/preview/MMPreviewActivity.java b/chat/src/main/java/cn/wildfire/chat/kit/preview/MMPreviewActivity.java index 180be31a7..e0b5e9e35 100644 --- a/chat/src/main/java/cn/wildfire/chat/kit/preview/MMPreviewActivity.java +++ b/chat/src/main/java/cn/wildfire/chat/kit/preview/MMPreviewActivity.java @@ -17,20 +17,22 @@ import android.widget.Toast; import android.widget.VideoView; +import androidx.annotation.NonNull; +import androidx.viewpager.widget.PagerAdapter; +import androidx.viewpager.widget.ViewPager; + import com.github.chrisbanes.photoview.PhotoView; import java.io.File; import java.lang.ref.WeakReference; import java.util.List; -import androidx.annotation.NonNull; -import androidx.viewpager.widget.PagerAdapter; -import androidx.viewpager.widget.ViewPager; import cn.wildfire.chat.app.Config; import cn.wildfire.chat.kit.GlideApp; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.third.utils.UIUtils; import cn.wildfire.chat.kit.utils.DownloadManager; +import cn.wildfire.chat.kit.widget.ViewPagerFixed; import cn.wildfirechat.chat.R; import cn.wildfirechat.message.ImageMessageContent; import cn.wildfirechat.message.VideoMessageContent; @@ -239,7 +241,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mm_preview); views = new SparseArray<>(3); - final ViewPager viewPager = findViewById(R.id.viewPager); + final ViewPagerFixed viewPager = findViewById(R.id.viewPager); viewPager.setAdapter(pagerAdapter); viewPager.setOffscreenPageLimit(1); viewPager.addOnPageChangeListener(pageChangeListener); diff --git a/chat/src/main/java/cn/wildfire/chat/kit/widget/ViewPagerFixed.java b/chat/src/main/java/cn/wildfire/chat/kit/widget/ViewPagerFixed.java new file mode 100644 index 000000000..74341d80f --- /dev/null +++ b/chat/src/main/java/cn/wildfire/chat/kit/widget/ViewPagerFixed.java @@ -0,0 +1,29 @@ +package cn.wildfire.chat.kit.widget; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.viewpager.widget.ViewPager; + +public class ViewPagerFixed extends ViewPager { + public ViewPagerFixed(@NonNull Context context) { + super(context); + } + + public ViewPagerFixed(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + try { + return super.onInterceptTouchEvent(ev); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + } + return false; + } +} diff --git a/emojilibrary/src/main/java/com/lqr/emoji/EmotionLayout.java b/emojilibrary/src/main/java/com/lqr/emoji/EmotionLayout.java index 682eef3e2..da709da7c 100755 --- a/emojilibrary/src/main/java/com/lqr/emoji/EmotionLayout.java +++ b/emojilibrary/src/main/java/com/lqr/emoji/EmotionLayout.java @@ -37,7 +37,7 @@ public class EmotionLayout extends LinearLayout implements View.OnClickListener private int mTabPosi = 0; private Context mContext; - private ViewPager mVpEmotioin; + private ViewPagerFixed mVpEmotioin; private LinearLayout mLlPageNumber; private LinearLayout mLlTabContainer; private RelativeLayout mRlEmotionAdd; diff --git a/emojilibrary/src/main/java/com/lqr/emoji/ViewPagerFixed.java b/emojilibrary/src/main/java/com/lqr/emoji/ViewPagerFixed.java new file mode 100755 index 000000000..5d06507e5 --- /dev/null +++ b/emojilibrary/src/main/java/com/lqr/emoji/ViewPagerFixed.java @@ -0,0 +1,38 @@ +package com.lqr.emoji; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; + +import androidx.viewpager.widget.ViewPager; + +public class ViewPagerFixed extends ViewPager { + + public ViewPagerFixed(Context context) { + super(context); + } + + public ViewPagerFixed(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public boolean onTouchEvent(MotionEvent ev) { + try { + return super.onTouchEvent(ev); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + } + return false; + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + try { + return super.onInterceptTouchEvent(ev); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + } + return false; + } +}