Skip to content

Commit

Permalink
fix viewpager onInterceptTouchEvent issue
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed Apr 26, 2019
1 parent dc337f0 commit ffb049d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
import android.content.Intent;
import android.widget.FrameLayout;

import androidx.fragment.app.FragmentActivity;

import com.afollestad.materialdialogs.MaterialDialog;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
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<ConversationExt> exts;

private boolean hideOnScroll = true;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions chat/src/main/java/cn/wildfire/chat/kit/widget/ViewPagerFixed.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions emojilibrary/src/main/java/com/lqr/emoji/ViewPagerFixed.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit ffb049d

Please sign in to comment.