Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
yrom committed Sep 24, 2013
2 parents a77c89c + 898244d commit 39d3bcd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 21 deletions.
Expand Up @@ -14,8 +14,6 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

public class SwipeBackLayout extends FrameLayout {
/**
* Minimum velocity that will be detected as a fling
Expand Down Expand Up @@ -69,8 +67,10 @@ public class SwipeBackLayout extends FrameLayout {

private static final int OVERSCROLL_DISTANCE = 10;

private static final int[] EDGE_FLAGS = {EDGE_LEFT, EDGE_RIGHT, EDGE_BOTTOM, EDGE_ALL};

private int mEdgeFlag;

/**
* Threshold of scroll, we will close the activity, when scrollPercent over
* this value;
Expand Down Expand Up @@ -119,19 +119,30 @@ public SwipeBackLayout(Context context) {
public SwipeBackLayout(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.SwipeBackLayoutStyle);
}

public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());

TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.SwipeBackLayout,defStyle,0);

int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1);
if(edgeSize >0 )
setEdgeSize(edgeSize);
int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)];
setEdgeTrackingEnabled(mode);

int shadowLeft = a.getResourceId(R.styleable.SwipeBackLayout_shadow_left, R.drawable.shadow_left);
int shadowRight = a.getResourceId(R.styleable.SwipeBackLayout_shadow_right, R.drawable.shadow_right);
int shadowBottom = a.getResourceId(R.styleable.SwipeBackLayout_shadow_bottom, R.drawable.shadow_bottom);
setShadow(shadowLeft, EDGE_LEFT);
setShadow(shadowRight, EDGE_RIGHT);
setShadow(shadowBottom, EDGE_BOTTOM);
a.recycle();
final float density = getResources().getDisplayMetrics().density;
final float minVel = MIN_FLING_VELOCITY * density;

mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());
mDragHelper.setMinVelocity(minVel);
setEdgeTrackingEnabled(EDGE_LEFT);

setShadow(R.drawable.shadow_left, EDGE_LEFT);
setShadow(R.drawable.shadow_right, EDGE_RIGHT);
setShadow(R.drawable.shadow_bottom, EDGE_BOTTOM);
}

/**
Expand Down Expand Up @@ -315,6 +326,7 @@ public boolean onTouchEvent(MotionEvent event) {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
mInLayout = true;
if(mContentView != null)
mContentView.layout(mContentLeft, mContentTop,
mContentLeft + mContentView.getMeasuredWidth(),
mContentTop + mContentView.getMeasuredHeight());
Expand Down Expand Up @@ -459,6 +471,7 @@ public void onViewPositionChanged(View changedView, int left, int top, int dx, i
}

if (mScrollPercent >= 1) {
if(!mActivity.isFinishing())
mActivity.finish();
}
}
Expand Down
Expand Up @@ -97,7 +97,7 @@ public class ViewDragHelper {
*/
public static final int DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;

private static final int EDGE_SIZE = 20; // dp
public static final int EDGE_SIZE = 20; // dp

private static final int BASE_SETTLE_DURATION = 256; // ms

Expand Down
Expand Up @@ -3,6 +3,7 @@
import me.imid.swipebacklayout.lib.SwipeBackLayout;
import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;

/**
Expand All @@ -21,7 +22,7 @@ public SwipeBackActivityHelper(Activity activity) {
public void onActivtyCreate(){
mActivity.getWindow().setBackgroundDrawable(new ColorDrawable(0));
mActivity.getWindow().getDecorView().setBackgroundDrawable(null);
mSwipeBackLayout = new SwipeBackLayout(mActivity);
mSwipeBackLayout = (SwipeBackLayout) LayoutInflater.from(mActivity).inflate(me.imid.swipebacklayout.lib.R.layout.swipeback_layout,null);
}

public void onPostCreate(){
Expand Down
6 changes: 6 additions & 0 deletions library/src/main/res/layout/swipeback_layout.xml
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<me.imid.swipebacklayout.lib.SwipeBackLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent" />

15 changes: 10 additions & 5 deletions library/src/main/res/values/attrs.xml
@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SwipeBackLayout">
<attr name="EdgeSize" format="dimension"/>
<attr name="EdgeFlag" format="enum"/>
<attr name="ShadowLeft" format="reference"/>
<attr name="ShadowRight" format="reference"/>
<attr name="ShadowBottom" format="reference"/>
<attr name="edge_size" format="dimension"/>
<attr name="edge_flag">
<enum name="left" value="0" />
<enum name="right" value="1" />
<enum name="bottom" value="2" />
<enum name="all" value="3" />
</attr>
<attr name="shadow_left" format="reference"/>
<attr name="shadow_right" format="reference"/>
<attr name="shadow_bottom" format="reference"/>
</declare-styleable>

<attr name="SwipeBackLayoutStyle" format="reference"/>
Expand Down
8 changes: 4 additions & 4 deletions library/src/main/res/values/styles.xml
Expand Up @@ -2,10 +2,10 @@
<resources>

<style name="SwipeBackLayout">
<item name="EdgeSize">20dip</item>
<item name="ShadowLeft">@drawable/shadow_left</item>
<item name="ShadowRight">@drawable/shadow_right</item>
<item name="ShadowBottom">@drawable/shadow_bottom</item>
<item name="edge_size">50dip</item>
<item name="shadow_left">@drawable/shadow_left</item>
<item name="shadow_right">@drawable/shadow_right</item>
<item name="shadow_bottom">@drawable/shadow_bottom</item>
</style>

</resources>

0 comments on commit 39d3bcd

Please sign in to comment.