Skip to content

Commit

Permalink
Merge pull request #2 from Kaufland/bugfix/restore-position-keyboard-…
Browse files Browse the repository at this point in the history
…hide

# Restore swipe position on Layout
  • Loading branch information
sbra0902 authored Jun 21, 2017
2 parents 3fa9ae9 + c0c05f0 commit 327e089
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kaufland.com.demo.example;

import android.inputmethodservice.Keyboard;
import android.os.Looper;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class DraggingProxy {
@Bean
protected SwipeViewLayouter mSwipeViewLayouter;

@Bean
protected LayoutCache mLayoutCache;

private boolean isInitilized;


Expand Down Expand Up @@ -136,4 +139,11 @@ public int getSurfaceOpenOffsetByDragView(int dragView) {
return mSwipeViewLayouter.getViewEngines().get(dragView).getOpenOffset();
}

public void captureChildrenBound() {
mLayoutCache.captureChildrenBound(mSwipeViewLayouter.getViews().values());
}

public void restoreChildrenBound() {
mLayoutCache.restoreOnLayout();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package kaufland.com.swipelibrary;

import android.graphics.PointF;
import android.view.View;

import org.androidannotations.annotations.EBean;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
* Created by sbra0902 on 21.06.17.
*/
@EBean
public class LayoutCache {


Map<View, PointF> mLayoutCache = new HashMap<>();


public void restoreOnLayout(){

for (View child : mLayoutCache.keySet()){

PointF restorePoint = mLayoutCache.get(child);

if(restorePoint != null){
child.setX(restorePoint.x);
child.setY(restorePoint.y);
}

}

}



public void captureChildrenBound(Collection<View> views){

for (View child : views) {
PointF point = mLayoutCache.get(child);
if(point==null){
point = new PointF();
mLayoutCache.put(child, point);
}

point.x = child.getX();
point.y = child.getY();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class SwipeLayout extends FrameLayout {
@Bean
protected DraggingProxy mDraggingProxy;

@Bean
protected LayoutCache mLayoutCache;

private KDragViewHelper mDragHelper;

private SwipeListener mSwipeListener;
Expand All @@ -56,7 +59,6 @@ public class SwipeLayout extends FrameLayout {

private float mDragHelperTouchSlop;


public interface SwipeListener {
void onSwipeOpened(SwipeState.DragViewState openedDragView, boolean isFullSwipe);

Expand Down Expand Up @@ -247,6 +249,12 @@ public void run() {

}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
mDraggingProxy.restoreChildrenBound();
}

private class SwipeDragViewHelper extends ViewDragHelper.Callback {

private ViewGroup parent;
Expand All @@ -264,6 +272,12 @@ public boolean tryCaptureView(View child, int pointerId) {
return mDraggingProxy.isCapturedViewDraggable(child);
}

@Override
public void onViewDragStateChanged(int state) {
if(state == 0){
mDraggingProxy.captureChildrenBound();
}
}

@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
Expand Down

0 comments on commit 327e089

Please sign in to comment.