Optimize the implement when surface or bottom not a GroupView
This commit is contained in:
parent
8fea955083
commit
b460d4dd47
|
|
@ -91,17 +91,12 @@
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<TextView
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:background="@drawable/white"
|
android:background="@drawable/white"
|
||||||
|
android:tag="Hover"
|
||||||
|
android:text="要有最樸素的生活和最遙遠的夢想,即使明天天寒地凍,山高水遠,路遠馬亡。"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:tag="Hover"
|
|
||||||
android:text="要有最樸素的生活和最遙遠的夢想,即使明天天寒地凍,山高水遠,路遠馬亡。"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</com.daimajia.swipe.SwipeLayout>
|
</com.daimajia.swipe.SwipeLayout>
|
||||||
|
|
|
||||||
|
|
@ -560,10 +560,10 @@ public class SwipeLayout extends FrameLayout {
|
||||||
*/
|
*/
|
||||||
private void safeBottomView() {
|
private void safeBottomView() {
|
||||||
Status status = getOpenStatus();
|
Status status = getOpenStatus();
|
||||||
List<ViewGroup> bottoms = getBottomViews();
|
List<View> bottoms = getBottomViews();
|
||||||
|
|
||||||
if (status == Status.Close) {
|
if (status == Status.Close) {
|
||||||
for (ViewGroup bottom : bottoms) {
|
for (View bottom : bottoms) {
|
||||||
if (bottom.getVisibility() != INVISIBLE) bottom.setVisibility(INVISIBLE);
|
if (bottom.getVisibility() != INVISIBLE) bottom.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -696,13 +696,6 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void addView(View child, int index, ViewGroup.LayoutParams params) {
|
public void addView(View child, int index, ViewGroup.LayoutParams params) {
|
||||||
//the child should be viewGroup, convert child here
|
|
||||||
if(!(child instanceof ViewGroup)){
|
|
||||||
WrapGroup childContain = new WrapGroup(getContext());
|
|
||||||
childContain.addView(child);
|
|
||||||
child = childContain;
|
|
||||||
}
|
|
||||||
|
|
||||||
int gravity = Gravity.NO_GRAVITY;
|
int gravity = Gravity.NO_GRAVITY;
|
||||||
try {
|
try {
|
||||||
gravity = (Integer) params.getClass().getField("gravity").get(params);
|
gravity = (Integer) params.getClass().getField("gravity").get(params);
|
||||||
|
|
@ -762,11 +755,6 @@ public class SwipeLayout extends FrameLayout {
|
||||||
" ChildCount:" + childCount +
|
" ChildCount:" + childCount +
|
||||||
", mDragEdges.size():"+ mDragEdges.size());
|
", mDragEdges.size():"+ mDragEdges.size());
|
||||||
}
|
}
|
||||||
for (int i = 0; i < childCount; i++) {
|
|
||||||
if (!(getChildAt(i) instanceof ViewGroup)) {
|
|
||||||
throw new IllegalArgumentException("All the children in SwipeLayout must be an instance of ViewGroup");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mShowMode == ShowMode.PullOut)
|
if (mShowMode == ShowMode.PullOut)
|
||||||
layoutPullOut();
|
layoutPullOut();
|
||||||
|
|
@ -1134,8 +1122,8 @@ public class SwipeLayout extends FrameLayout {
|
||||||
public boolean onDoubleTap(MotionEvent e) {
|
public boolean onDoubleTap(MotionEvent e) {
|
||||||
if (mDoubleClickListener != null) {
|
if (mDoubleClickListener != null) {
|
||||||
View target;
|
View target;
|
||||||
ViewGroup bottom = getBottomViews().get(mCurrentDirectionIndex);
|
View bottom = getBottomViews().get(mCurrentDirectionIndex);
|
||||||
ViewGroup surface = getSurfaceView();
|
View surface = getSurfaceView();
|
||||||
if (e.getX() > bottom.getLeft() && e.getX() < bottom.getRight() && e.getY() > bottom.getTop()
|
if (e.getX() > bottom.getLeft() && e.getX() < bottom.getRight() && e.getY() > bottom.getTop()
|
||||||
&& e.getY() < bottom.getBottom()) {
|
&& e.getY() < bottom.getBottom()) {
|
||||||
target = bottom;
|
target = bottom;
|
||||||
|
|
@ -1193,37 +1181,37 @@ public class SwipeLayout extends FrameLayout {
|
||||||
return mShowMode;
|
return mShowMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ViewGroup getSurfaceView() {
|
public View getSurfaceView() {
|
||||||
return (ViewGroup) getChildAt(getChildCount() - 1);
|
return (View) getChildAt(getChildCount() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return all bottomViews.
|
* @return all bottomViews.
|
||||||
*/
|
*/
|
||||||
public List<ViewGroup> getBottomViews() {
|
public List<View> getBottomViews() {
|
||||||
List<ViewGroup> lvg = new ArrayList<ViewGroup>();
|
List<View> lvg = new ArrayList<View>();
|
||||||
// If the user has provided a map for views to
|
// If the user has provided a map for views to
|
||||||
if (mBottomViewIdsSet) {
|
if (mBottomViewIdsSet) {
|
||||||
lvg.addAll(Arrays.asList(new ViewGroup[mDragEdges.size()]));
|
lvg.addAll(Arrays.asList(new View[mDragEdges.size()]));
|
||||||
|
|
||||||
if (mDragEdges.contains(DragEdge.Left)) {
|
if (mDragEdges.contains(DragEdge.Left)) {
|
||||||
lvg.set(mLeftIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Left))));
|
lvg.set(mLeftIndex, ((View) findViewById(mBottomViewIdMap.get(DragEdge.Left))));
|
||||||
}
|
}
|
||||||
if (mDragEdges.contains(DragEdge.Top)) {
|
if (mDragEdges.contains(DragEdge.Top)) {
|
||||||
lvg.set(mTopIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Top))));
|
lvg.set(mTopIndex, ((View) findViewById(mBottomViewIdMap.get(DragEdge.Top))));
|
||||||
}
|
}
|
||||||
if (mDragEdges.contains(DragEdge.Right)) {
|
if (mDragEdges.contains(DragEdge.Right)) {
|
||||||
lvg.set(mRightIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Right))));
|
lvg.set(mRightIndex, ((View) findViewById(mBottomViewIdMap.get(DragEdge.Right))));
|
||||||
}
|
}
|
||||||
if (mDragEdges.contains(DragEdge.Bottom)) {
|
if (mDragEdges.contains(DragEdge.Bottom)) {
|
||||||
lvg.set(mBottomIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Bottom))));
|
lvg.set(mBottomIndex, ((View) findViewById(mBottomViewIdMap.get(DragEdge.Bottom))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Default behaviour is to simply use the first n-1 children in the order they're listed in the layout
|
// Default behaviour is to simply use the first n-1 children in the order they're listed in the layout
|
||||||
// and return them in
|
// and return them in
|
||||||
else {
|
else {
|
||||||
for (int i = 0; i < (getChildCount() - 1); i++) {
|
for (int i = 0; i < (getChildCount() - 1); i++) {
|
||||||
lvg.add((ViewGroup) getChildAt(i));
|
lvg.add((View) getChildAt(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lvg;
|
return lvg;
|
||||||
|
|
@ -1418,7 +1406,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open(boolean smooth, boolean notify) {
|
public void open(boolean smooth, boolean notify) {
|
||||||
ViewGroup surface = getSurfaceView(), bottom = getBottomViews().get(mCurrentDirectionIndex);
|
View surface = getSurfaceView(), bottom = getBottomViews().get(mCurrentDirectionIndex);
|
||||||
int dx, dy;
|
int dx, dy;
|
||||||
Rect rect = computeSurfaceLayoutArea(true);
|
Rect rect = computeSurfaceLayoutArea(true);
|
||||||
if (smooth) {
|
if (smooth) {
|
||||||
|
|
@ -1501,7 +1489,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
* @param notify if notify all the listeners.
|
* @param notify if notify all the listeners.
|
||||||
*/
|
*/
|
||||||
public void close(boolean smooth, boolean notify) {
|
public void close(boolean smooth, boolean notify) {
|
||||||
ViewGroup surface = getSurfaceView();
|
View surface = getSurfaceView();
|
||||||
int dx, dy;
|
int dx, dy;
|
||||||
if (smooth)
|
if (smooth)
|
||||||
mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(), getPaddingTop());
|
mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(), getPaddingTop());
|
||||||
|
|
@ -1666,11 +1654,4 @@ public class SwipeLayout extends FrameLayout {
|
||||||
mOnLayoutListeners.get(i).onLayout(this);
|
mOnLayoutListeners.get(i).onLayout(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if child is not viewGroup, this group will wrap it
|
|
||||||
public class WrapGroup extends FrameLayout{
|
|
||||||
public WrapGroup(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue