#23 support selector
This commit is contained in:
parent
c70c78f607
commit
0d3dc52c90
|
|
@ -19,7 +19,6 @@ public class ListViewExample extends Activity {
|
|||
|
||||
private ListView mListView;
|
||||
private ListViewAdapter mAdapter;
|
||||
private int mPositionToTest;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@drawable/hover_border_pressed" android:state_pressed="true"/>
|
||||
<item android:drawable="@drawable/hover_border_pressed" android:state_focused="true"/>
|
||||
<item android:drawable="@drawable/hover_border_normal"/>
|
||||
|
||||
</selector>
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:innerRadius="10dp" >
|
||||
|
||||
<stroke
|
||||
android:width="10dp"
|
||||
android:color="#f3f300" />
|
||||
|
||||
<solid android:color="#f9f9f9" />
|
||||
|
||||
</shape>
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="#e2e2e2" />
|
||||
|
||||
<solid android:color="#f9f9f9" />
|
||||
|
||||
<gradient
|
||||
android:endColor="#66E8E8E8"
|
||||
android:gradientRadius="150"
|
||||
android:startColor="#ffffffff"
|
||||
android:type="radial" />
|
||||
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@color/backgroundColorPress" android:state_pressed="true"/>
|
||||
<item android:drawable="@color/backgroundColorPress" android:state_focused="true"/>
|
||||
<item android:drawable="@color/backgroundColor"/>
|
||||
|
||||
</selector>
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
android:verticalSpacing="10dp"
|
||||
android:horizontalSpacing="10dp"
|
||||
android:numColumns="2"
|
||||
android:listSelector="@drawable/hover_background"
|
||||
android:listSelector="@drawable/item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,55 +1,58 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
|
||||
<com.daimajia.swipe.SwipeLayout
|
||||
android:id="@+id/swipe"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="800dp"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:background="#FF5534"
|
||||
android:tag="Bottom3"
|
||||
android:weightSum="10"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/item"
|
||||
android:layout_height="match_parent">
|
||||
<com.daimajia.swipe.SwipeLayout
|
||||
android:id="@+id/swipe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp">
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="27dp"
|
||||
android:layout_height="30dp" />
|
||||
<TextView
|
||||
android:text="Delete Item?"
|
||||
android:textSize="17sp"
|
||||
android:textColor="#fff"
|
||||
android:layout_weight="5"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content" />
|
||||
<Button
|
||||
android:id="@+id/delete"
|
||||
android:textColor="#FF5534"
|
||||
android:background="#ffffff"
|
||||
android:text="Yes,Delete"
|
||||
android:layout_weight="4"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp" />
|
||||
</LinearLayout>
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="#ffffff"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:id="@+id/position"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:tag="Hover"
|
||||
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
|
||||
<LinearLayout
|
||||
android:background="#FF5534"
|
||||
android:tag="Bottom3"
|
||||
android:weightSum="10"
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
android:layout_height="80dp">
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="27dp"
|
||||
android:layout_height="30dp" />
|
||||
<TextView
|
||||
android:text="Delete Item?"
|
||||
android:textSize="17sp"
|
||||
android:textColor="#fff"
|
||||
android:layout_weight="5"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content" />
|
||||
<Button
|
||||
android:id="@+id/delete"
|
||||
android:textColor="#FF5534"
|
||||
android:background="#ffffff"
|
||||
android:text="Yes,Delete"
|
||||
android:layout_weight="4"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:id="@+id/position"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:tag="Hover"
|
||||
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="@drawable/item"
|
||||
android:layout_width="match_parent" android:layout_height="80dp">
|
||||
<LinearLayout
|
||||
android:tag="Bottom1"
|
||||
|
|
@ -30,7 +31,7 @@
|
|||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="#ffffff"
|
||||
android:background="@drawable/item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="backgroundColor">#E8E8E0</color>
|
||||
<color name="backgroundColorPress">#DBDBD3</color>
|
||||
</resources>
|
||||
|
|
@ -654,13 +654,12 @@ public class SwipeLayout extends FrameLayout {
|
|||
}else{
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
mTouchConsumedByChild = false;
|
||||
}
|
||||
|
||||
if(mTouchConsumedByChild) return false;
|
||||
if(mTouchConsumedByChild) return false;
|
||||
return mDragHelper.shouldInterceptTouchEvent(ev);
|
||||
}
|
||||
|
||||
|
|
@ -718,12 +717,23 @@ public class SwipeLayout extends FrameLayout {
|
|||
int action = event.getActionMasked();
|
||||
ViewParent parent = getParent();
|
||||
gestureDetector.onTouchEvent(event);
|
||||
Status status = getOpenStatus();
|
||||
ViewGroup touching = null;
|
||||
if(status == Status.Close){
|
||||
touching = getSurfaceView();
|
||||
}else if(status == Status.Open){
|
||||
touching = getBottomView();
|
||||
}
|
||||
switch (action){
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mDragHelper.processTouchEvent(event);
|
||||
parent.requestDisallowInterceptTouchEvent(true);
|
||||
sX = event.getRawX();
|
||||
sY = event.getRawY();
|
||||
|
||||
if(touching != null)
|
||||
touching.setPressed(true);
|
||||
|
||||
return true;
|
||||
case MotionEvent.ACTION_MOVE:{
|
||||
if(sX == -1 || sY == -1){
|
||||
|
|
@ -737,18 +747,22 @@ public class SwipeLayout extends FrameLayout {
|
|||
sY = event.getRawY();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(touching != null)
|
||||
touching.setPressed(false);
|
||||
|
||||
float distanceX = event.getRawX() - sX;
|
||||
float distanceY = event.getRawY() - sY;
|
||||
float angle = Math.abs(distanceY / distanceX);
|
||||
angle = (float)Math.toDegrees(Math.atan(angle));
|
||||
Status status = getOpenStatus();
|
||||
|
||||
boolean doNothing = false;
|
||||
if(mDragEdge == DragEdge.Right){
|
||||
boolean suitable = (status == Status.Open && distanceX > 0) || (status == Status.Close && distanceX < 0);
|
||||
suitable = suitable || (status == Status.Middle);
|
||||
|
||||
if(angle > 30 || !suitable){
|
||||
parent.requestDisallowInterceptTouchEvent(false);
|
||||
return false;
|
||||
doNothing = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -757,8 +771,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
suitable = suitable || status == Status.Middle;
|
||||
|
||||
if(angle > 30 || ! suitable){
|
||||
parent.requestDisallowInterceptTouchEvent(false);
|
||||
return false;
|
||||
doNothing = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -767,8 +780,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
suitable = suitable || status == Status.Middle;
|
||||
|
||||
if(angle < 60 || ! suitable){
|
||||
parent.requestDisallowInterceptTouchEvent(false);
|
||||
return false;
|
||||
doNothing = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -777,13 +789,17 @@ public class SwipeLayout extends FrameLayout {
|
|||
suitable = suitable || status == Status.Middle;
|
||||
|
||||
if(angle < 60 || ! suitable){
|
||||
parent.requestDisallowInterceptTouchEvent(false);
|
||||
return false;
|
||||
doNothing = true;
|
||||
}
|
||||
}
|
||||
|
||||
parent.requestDisallowInterceptTouchEvent(true);
|
||||
mDragHelper.processTouchEvent(event);
|
||||
if(doNothing){
|
||||
parent.requestDisallowInterceptTouchEvent(false);
|
||||
return false;
|
||||
}else{
|
||||
parent.requestDisallowInterceptTouchEvent(true);
|
||||
mDragHelper.processTouchEvent(event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MotionEvent.ACTION_UP:
|
||||
|
|
@ -791,6 +807,9 @@ public class SwipeLayout extends FrameLayout {
|
|||
{
|
||||
sX = -1;
|
||||
sY = -1;
|
||||
if(touching != null){
|
||||
touching.setPressed(false);
|
||||
}
|
||||
}
|
||||
default:
|
||||
parent.requestDisallowInterceptTouchEvent(true);
|
||||
|
|
|
|||
Loading…
Reference in New Issue