Skip to content

Commit

Permalink
Merge pull request #595 from AllenCoder/master
Browse files Browse the repository at this point in the history
fix click bug and rename
  • Loading branch information
CymChad authored Dec 7, 2016
2 parents 509d167 + b459aba commit 51f8a91
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void initAdapter() {
mQuickAdapter.openLoadAnimation();
mRecyclerView.addOnItemTouchListener(new OnItemChildClickListener() {
@Override
public void SimpleOnItemChildClick(BaseQuickAdapter adapter, View view, int position) {
public void onSimpleItemChildClick(BaseQuickAdapter adapter, View view, int position) {
String content = null;
Status status = (Status) adapter.getItem(position);
switch (view.getId()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void initAdapter() {
mRecyclerView.setAdapter(mQuickAdapter);
mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
@Override
public void SimpleOnItemClick(BaseQuickAdapter adapter, View view, int position) {
public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(HeaderAndFooterUseActivity.this, "" + Integer.toString(position), Toast.LENGTH_LONG).show();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void onCreate(Bundle savedInstanceState) {
homeAdapter.openLoadAnimation();
mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
@Override
public void SimpleOnItemClick(BaseQuickAdapter adapter, View view, int position) {
public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
Intent intent = new Intent(HomeActivity.this, ACTIVITY[position]);
startActivity(intent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
initAdapter();
mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
@Override
public void SimpleOnItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
Log.d(TAG, "SimpleOnItemClick: ");
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void initAdapter() {

mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
@Override
public void SimpleOnItemClick(BaseQuickAdapter adapter, View view, int position) {
public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
Toast.makeText(PullToRefreshUseActivity.this, Integer.toString(position), Toast.LENGTH_LONG).show();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -13,6 +14,7 @@
import com.chad.baserecyclerviewadapterhelper.adapter.QuickClickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.util.TouchEventUtil;

/**
* create by AllenCoder
Expand All @@ -23,6 +25,7 @@ public class RecyclerClickItemActivity extends Activity {
private QuickClickAdapter mQuickAdapter;
private static final int PAGE_SIZE = 10;
private static String TAG = "RecyclerClickItemActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -40,7 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {
mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {

@Override
public void SimpleOnItemClick(BaseQuickAdapter adapter, View view, int position) {
public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(RecyclerClickItemActivity.this, "" + Integer.toString(position), Toast.LENGTH_SHORT).show();
}

Expand All @@ -49,76 +52,36 @@ public void onItemChildClick(BaseQuickAdapter adapter, View view, int position)
super.onItemChildClick(adapter, view, position);
switch (view.getId()) {
case R.id.tweetAvatar:
Toast.makeText(RecyclerClickItemActivity.this, "The " + Integer.toString(position)+" tweetAvatar is clicked", Toast.LENGTH_SHORT).show();
Toast.makeText(RecyclerClickItemActivity.this, "The " + Integer.toString(position) + " tweetAvatar is clicked", Toast.LENGTH_SHORT).show();
break;
case R.id.tweetName:
Toast.makeText(RecyclerClickItemActivity.this, "The " + Integer.toString(position)+" tweetName is clicked", Toast.LENGTH_SHORT).show();
Toast.makeText(RecyclerClickItemActivity.this, "The " + Integer.toString(position) + " tweetName is clicked", Toast.LENGTH_SHORT).show();
break;
default:
break;
}

}


@Override
public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
super.onItemLongClick(adapter, view, position);
Toast.makeText(RecyclerClickItemActivity.this,"The " + Integer.toString(position)+ " Item is LongClick ", Toast.LENGTH_SHORT).show();
Toast.makeText(RecyclerClickItemActivity.this, "The " + Integer.toString(position) + " Item is LongClick ", Toast.LENGTH_SHORT).show();

}

@Override
public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
super.onItemChildLongClick(adapter, view, position);
Toast.makeText(RecyclerClickItemActivity.this, "The "+ Integer.toString(position)+" view itemchild " + "is LongClick " + Integer.toString(position), Toast.LENGTH_SHORT).show();
Toast.makeText(RecyclerClickItemActivity.this, "The " + Integer.toString(position) + " view itemchild " + "is LongClick " + Integer.toString(position), Toast.LENGTH_SHORT).show();

}
});
/**
* this is sample code
*/
/* mRecyclerView.addOnItemTouchListener(new OnItemChildClickListener() {
@Override
public void SimpleOnItemChildClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(RecyclerClickItemActivity.this, "" + Integer.toString(position), Toast.LENGTH_SHORT).show();
}
});
mRecyclerView.addOnItemTouchListener(new OnItemLongClickListener() {
@Override
public void SimpleOnItemLongClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(RecyclerClickItemActivity.this, "" + Integer.toString(position), Toast.LENGTH_SHORT).show();
}
});
mRecyclerView.addOnItemTouchListener(new OnItemChildLongClickListener() {
@Override
public void SimpleOnItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(RecyclerClickItemActivity.this, "" + Integer.toString(position), Toast.LENGTH_SHORT).show();
}
});
mRecyclerView.addOnItemTouchListener(new SimpleClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(RecyclerClickItemActivity.this, "" + Integer.toString(position), Toast.LENGTH_SHORT).show();
}
@Override
public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(RecyclerClickItemActivity.this, "" + Integer.toString(position), Toast.LENGTH_SHORT).show();
}
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(RecyclerClickItemActivity.this, "" + Integer.toString(position), Toast.LENGTH_SHORT).show();
}

@Override
public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(RecyclerClickItemActivity.this, "" + Integer.toString(position), Toast.LENGTH_SHORT).show();
}
});*/
}

private View getHeadView() {
Expand All @@ -129,10 +92,12 @@ private View getHeadView() {
@Override
public void onClick(View v) {
Toast.makeText(RecyclerClickItemActivity.this, "click headView", Toast.LENGTH_LONG).show();
Log.e(TAG, "点击了顶部: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
}
});
return view;
}

private View getFootView() {
View view = getLayoutInflater().inflate(R.layout.head_view, null);
view.findViewById(R.id.tv).setVisibility(View.GONE);
Expand All @@ -141,20 +106,33 @@ private View getFootView() {
@Override
public void onClick(View v) {
Toast.makeText(RecyclerClickItemActivity.this, "click FootView", Toast.LENGTH_LONG).show();
Log.e(TAG, "点击了底部: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
}
});

return view;
}

@Override
public boolean dispatchTouchEvent(final MotionEvent ev) {
Log.w(TAG, "---------------------------------------------------------------");
Log.w(TAG, "dispatchTouchEvent: "+ TouchEventUtil.getTouchAction(ev.getAction()));
return super.dispatchTouchEvent(ev);
}



private void initAdapter() {
mQuickAdapter = new QuickClickAdapter(PAGE_SIZE);
mQuickAdapter.openLoadAnimation();
mRecyclerView.setAdapter(mQuickAdapter);
}


@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return super.dispatchTouchEvent(ev);
public boolean onTouchEvent(final MotionEvent event) {
Log.d(TAG, "onTouchEvent: "+TouchEventUtil.getTouchAction(event.getAction()));
return super.onTouchEvent(event);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected void onCreate(Bundle savedInstanceState) {
mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {

@Override
public void SimpleOnItemClick(BaseQuickAdapter adapter, View view, int position) {
public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
MySection mySection = mData.get(position);
if (mySection.isHeader)
Toast.makeText(SectionUseActivity.this, mySection.header, Toast.LENGTH_LONG).show();
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/head_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/touch_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
Expand All @@ -16,4 +17,4 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"/>
</LinearLayout>
</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) {

@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
SimpleOnItemChildClick(adapter, view, position);
onSimpleItemChildClick(adapter, view, position);
}

@Override
public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {

}

public abstract void SimpleOnItemChildClick(BaseQuickAdapter adapter, View view, int position);
public abstract void onSimpleItemChildClick(BaseQuickAdapter adapter, View view, int position);

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onItemChildClick(BaseQuickAdapter adapter, View view, int position)

@Override
public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
SimpleOnItemChildLongClick(adapter,view,position);
onSimpleItemChildLongClick(adapter,view,position);
}
public abstract void SimpleOnItemChildLongClick(BaseQuickAdapter adapter, View view, int position);
public abstract void onSimpleItemChildLongClick(BaseQuickAdapter adapter, View view, int position);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class OnItemClickListener extends SimpleClickListener {

@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
SimpleOnItemClick(adapter,view,position);
onSimpleItemClick(adapter,view,position);
}

@Override
Expand All @@ -34,5 +34,5 @@ public void onItemChildClick(BaseQuickAdapter adapter, View view, int position)
public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {

}
public abstract void SimpleOnItemClick(BaseQuickAdapter adapter, View view, int position);
public abstract void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

@Override
public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
SimpleOnItemLongClick( adapter, view, position);
onSimpleItemLongClick( adapter, view, position);
}

@Override
Expand All @@ -31,5 +31,5 @@ public void onItemChildClick(BaseQuickAdapter adapter, View view, int position)
@Override
public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
}
public abstract void SimpleOnItemLongClick(BaseQuickAdapter adapter, View view, int position);
public abstract void onSimpleItemLongClick(BaseQuickAdapter adapter, View view, int position);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public abstract class SimpleClickListener implements RecyclerView.OnItemTouchLis

@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

if (recyclerView == null) {
this.recyclerView = rv;
this.baseQuickAdapter = (BaseQuickAdapter) recyclerView.getAdapter();
Expand All @@ -51,15 +50,12 @@ public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
if (!mGestureDetector.onTouchEvent(e) && e.getActionMasked() == MotionEvent.ACTION_UP && mIsShowPress) {
if (mPressedView!=null){
BaseViewHolder vh = (BaseViewHolder) recyclerView.getChildViewHolder(mPressedView);
if (vh == null || vh.getItemViewType() != LOADING_VIEW) {
if (vh == null ||!isHeaderOrFooterView(vh.getItemViewType())) {
mPressedView.setPressed(false);
}
mPressedView = null;
}
mIsShowPress = false;
mIsPrepressed = false;


}
return false;
}
Expand Down Expand Up @@ -102,7 +98,9 @@ public ItemTouchHelperGestureListener(RecyclerView recyclerView) {
@Override
public boolean onSingleTapUp(MotionEvent e) {
if (mIsPrepressed && mPressedView != null) {

if (recyclerView.getScrollState()!=RecyclerView.SCROLL_STATE_IDLE){
return false;
}
final View pressedView = mPressedView;
BaseViewHolder vh = (BaseViewHolder) recyclerView.getChildViewHolder(pressedView);

Expand Down Expand Up @@ -166,6 +164,9 @@ public void run() {
@Override
public void onLongPress(MotionEvent e) {
boolean isChildLongClick =false;
if (recyclerView.getScrollState()!=RecyclerView.SCROLL_STATE_IDLE){
return ;
}
if (mIsPrepressed && mPressedView != null) {
mPressedView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
BaseViewHolder vh = (BaseViewHolder) recyclerView.getChildViewHolder(mPressedView);
Expand Down Expand Up @@ -270,7 +271,10 @@ private boolean isHeaderOrFooterPosition(int position) {
int type = baseQuickAdapter.getItemViewType(position);
return (type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type == LOADING_VIEW);
}
private boolean isHeaderOrFooterView(int type) {

return (type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type == LOADING_VIEW);
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.chad.library.adapter.base.util;

import android.view.MotionEvent;

public class TouchEventUtil {

public static String getTouchAction(int actionId) {
String actionName = "Unknow:id=" + actionId;
switch (actionId) {
case MotionEvent.ACTION_DOWN:
actionName = "ACTION_DOWN";
break;
case MotionEvent.ACTION_MOVE:
actionName = "ACTION_MOVE";
break;
case MotionEvent.ACTION_UP:
actionName = "ACTION_UP";
break;
case MotionEvent.ACTION_CANCEL:
actionName = "ACTION_CANCEL";
break;
case MotionEvent.ACTION_OUTSIDE:
actionName = "ACTION_OUTSIDE";
break;
}
return actionName;
}

}

0 comments on commit 51f8a91

Please sign in to comment.