support double click
This commit is contained in:
parent
83bc638799
commit
e0b54dede3
|
|
@ -7,6 +7,7 @@ import android.view.View;
|
|||
import android.widget.AdapterView;
|
||||
import android.widget.GridView;
|
||||
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipedemo.adapter.GridViewAdapter;
|
||||
|
||||
public class GridViewExample extends Activity{
|
||||
|
|
@ -17,7 +18,7 @@ public class GridViewExample extends Activity{
|
|||
setContentView(R.layout.gridview);
|
||||
final GridView gridView = (GridView)findViewById(R.id.gridview);
|
||||
final GridViewAdapter adapter = new GridViewAdapter(this);
|
||||
|
||||
adapter.setMode(SwipeItemMangerImpl.Mode.Multiple);
|
||||
gridView.setAdapter(adapter);
|
||||
gridView.setSelected(false);
|
||||
gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.daimajia.swipedemo;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
|
@ -11,6 +12,7 @@ import android.view.View;
|
|||
import android.widget.AbsListView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipedemo.adapter.ListViewAdapter;
|
||||
|
|
@ -19,7 +21,7 @@ public class ListViewExample extends Activity {
|
|||
|
||||
private ListView mListView;
|
||||
private ListViewAdapter mAdapter;
|
||||
|
||||
private Context mContext = this;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -41,7 +43,7 @@ public class ListViewExample extends Activity {
|
|||
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Log.e("ListView", "onItemClick:" + position);
|
||||
Toast.makeText(mContext, "Click", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
mListView.setOnTouchListener(new View.OnTouchListener() {
|
||||
|
|
@ -54,7 +56,7 @@ public class ListViewExample extends Activity {
|
|||
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Log.e("ListView","onItemLongClick:" + position);
|
||||
Toast.makeText(mContext, "OnItemLongClickListener", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,19 +2,31 @@ package com.daimajia.swipedemo;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
|
||||
public class NestedExample extends Activity{
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.complicate_layout);
|
||||
findViewById(R.id.hhhhh).setOnClickListener(new View.OnClickListener() {
|
||||
SwipeLayout swipeLayout = (SwipeLayout)findViewById(R.id.test_swipe_swipe);
|
||||
swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
|
||||
@Override
|
||||
public void onDoubleClick(SwipeLayout layout, boolean surface) {
|
||||
Toast.makeText(getApplicationContext(), "DoubleClick", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
swipeLayout.findViewById(R.id.trash).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Log.e("Tag","got");
|
||||
Toast.makeText(getApplicationContext(), "Click", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.androidanimations.library.Techniques;
|
||||
import com.daimajia.androidanimations.library.YoYo;
|
||||
import com.daimajia.swipe.adapters.BaseSwipeAdapter;
|
||||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.adapters.BaseSwipeAdapter;
|
||||
import com.daimajia.swipedemo.R;
|
||||
|
||||
public class ListViewAdapter extends BaseSwipeAdapter {
|
||||
|
|
@ -36,6 +37,12 @@ public class ListViewAdapter extends BaseSwipeAdapter {
|
|||
YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash));
|
||||
}
|
||||
});
|
||||
swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
|
||||
@Override
|
||||
public void onDoubleClick(SwipeLayout layout, boolean surface) {
|
||||
Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,4 +6,6 @@
|
|||
<include layout="@layout/sampe_nested_scrollview" android:layout_height="80dp" android:layout_width="match_parent"/>
|
||||
<include layout="@layout/sampe_nested_seekbar" android:layout_height="80dp" android:layout_width="match_parent" android:layout_marginTop="20dp"/>
|
||||
<include layout="@layout/sampe_nested_edittext" android:layout_height="80dp" android:layout_width="match_parent" android:layout_marginTop="20dp"/>
|
||||
<include layout="@layout/sample_nested_parent" android:layout_height="80dp" android:layout_width="match_parent" android:layout_marginTop="20dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout android:id="@+id/parent_framelayout" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">
|
||||
<com.daimajia.swipe.SwipeLayout
|
||||
android:id="@+id/test_swipe_swipe"
|
||||
android:layout_width="match_parent" android:layout_height="80dp">
|
||||
<LinearLayout
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="match_parent">
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_width="match_parent"
|
||||
android:background="#FF3B30"
|
||||
android:paddingLeft="25dp"
|
||||
android:paddingRight="25dp"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="#ffffff"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:text="SeekBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
</FrameLayout>
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
# org.gradle.parallel=true
|
||||
|
||||
|
||||
VERSION_NAME=1.1.4
|
||||
VERSION_CODE=15
|
||||
VERSION_NAME=1.1.6
|
||||
VERSION_CODE=17
|
||||
GROUP=com.daimajia.swipelayout
|
||||
|
||||
ANDROID_BUILD_MIN_SDK_VERSION=8
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ public class SwipeLayout extends FrameLayout {
|
|||
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<View, ArrayList<OnRevealListener>>();
|
||||
private Map<View, Boolean> mShowEntirely = new HashMap<View, Boolean>();
|
||||
|
||||
private DoubleClickListener mDoubleClickListener;
|
||||
|
||||
private boolean mSwipeEnabled = true;
|
||||
|
||||
public static enum DragEdge {
|
||||
|
|
@ -126,7 +128,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
throw new IllegalArgumentException("Child does not belong to SwipeListener.");
|
||||
}
|
||||
|
||||
if(mShowEntirely.containsKey(child) == false){
|
||||
if(!mShowEntirely.containsKey(child)){
|
||||
mShowEntirely.put(child, false);
|
||||
}
|
||||
if(mRevealListeners.get(child) == null)
|
||||
|
|
@ -768,6 +770,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
}else if(status == Status.Open){
|
||||
touching = getBottomView();
|
||||
}
|
||||
|
||||
switch (action){
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mDragHelper.processTouchEvent(event);
|
||||
|
|
@ -909,7 +912,22 @@ public class SwipeLayout extends FrameLayout {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void performAdapterViewItemClick(MotionEvent e){
|
||||
ViewParent t = getParent();
|
||||
while(t != null) {
|
||||
if(t instanceof AdapterView){
|
||||
AdapterView view = (AdapterView)t;
|
||||
int p = view.getPositionForView(SwipeLayout.this);
|
||||
if( p != AdapterView.INVALID_POSITION &&
|
||||
view.performItemClick(view.getChildAt(p), p, view.getAdapter().getItemId(p)))
|
||||
return;
|
||||
}else{
|
||||
if(t instanceof View && ((View) t).performClick())
|
||||
return;
|
||||
}
|
||||
t = t.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
private GestureDetector gestureDetector = new GestureDetector(getContext(), new SwipeDetector());
|
||||
class SwipeDetector extends GestureDetector.SimpleOnGestureListener{
|
||||
|
|
@ -927,21 +945,18 @@ public class SwipeLayout extends FrameLayout {
|
|||
*/
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
ViewParent t = getParent();
|
||||
while(t != null) {
|
||||
if(t instanceof AdapterView){
|
||||
AdapterView view = (AdapterView)t;
|
||||
int p = view.getPositionForView(SwipeLayout.this);
|
||||
if( p != AdapterView.INVALID_POSITION &&
|
||||
view.performItemClick(view.getChildAt(p), p, view.getAdapter().getItemId(p)))
|
||||
return true;
|
||||
}else{
|
||||
if(t instanceof View && ((View) t).performClick())
|
||||
return true;
|
||||
}
|
||||
t = t.getParent();
|
||||
if(mDoubleClickListener == null){
|
||||
performAdapterViewItemClick(e);
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
if(mDoubleClickListener != null){
|
||||
performAdapterViewItemClick(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -949,6 +964,22 @@ public class SwipeLayout extends FrameLayout {
|
|||
performLongClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
if(mDoubleClickListener != null){
|
||||
View target;
|
||||
ViewGroup bottom = getBottomView();
|
||||
ViewGroup surface = getSurfaceView();
|
||||
if(e.getX() > bottom.getLeft() && e.getX() < bottom.getRight()
|
||||
&& e.getY() > bottom.getTop() && e.getY() < bottom.getBottom()){
|
||||
target = bottom;
|
||||
}else{
|
||||
target = surface;
|
||||
}
|
||||
mDoubleClickListener.onDoubleClick(SwipeLayout.this, target == surface);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDragEdge(DragEdge dragEdge){
|
||||
|
|
@ -1250,6 +1281,14 @@ public class SwipeLayout extends FrameLayout {
|
|||
return new Rect(bl, bt, br, bb);
|
||||
}
|
||||
|
||||
public void setOnDoubleClickListener(DoubleClickListener doubleClickListener){
|
||||
mDoubleClickListener = doubleClickListener;
|
||||
}
|
||||
|
||||
public interface DoubleClickListener {
|
||||
public void onDoubleClick(SwipeLayout layout, boolean surface);
|
||||
}
|
||||
|
||||
private int dp2px(float dp){
|
||||
return (int) (dp * getContext().getResources().getDisplayMetrics().density + 0.5f);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue