Skip to content

Commit

Permalink
Finished Drag positions from all directions (LEFT, RIGHT, TOP, BOTTOM)
Browse files Browse the repository at this point in the history
Still need to implement/fix edge only capturing
  • Loading branch information
r0adkll committed Feb 10, 2015
1 parent 9857bbc commit 4dd344c
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

local.properties
Slidr.iml
*.iml
.idea/libraries
.idea/encodings.xml
.idea/compiler.xml
Expand Down
6 changes: 3 additions & 3 deletions .idea/libraries/support_v4_21_0_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ protected void onCreate(Bundle savedInstanceState) {
SlidrConfig config = new SlidrConfig.Builder()
.primaryColor(primary)
.secondaryColor(secondary)
.position(SlidrPosition.RIGHT)
.position(SlidrPosition.LEFT)
.touchSize(Utils.dpToPx(this, 32))
.build();

// Attach the Slidr Mechanism to this activity
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/java/com/r0adkll/slidr/Slidr.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static SlidrInterface attach(final Activity activity, final int statusBar
// Setup the slider panel and attach it to the decor
final SliderPanel panel = new SliderPanel(activity, oldScreen);
panel.setId(R.id.slidable_panel);
oldScreen.setId(R.id.slidable_content);
panel.addView(oldScreen);
decorView.addView(panel, 0);

Expand Down Expand Up @@ -118,6 +119,7 @@ public static SlidrInterface attach(final Activity activity, final SlidrConfig c
// Setup the slider panel and attach it to the decor
final SliderPanel panel = new SliderPanel(activity, oldScreen, config);
panel.setId(R.id.slidable_panel);
oldScreen.setId(R.id.slidable_content);
panel.addView(oldScreen);
decorView.addView(panel, 0);

Expand Down
147 changes: 143 additions & 4 deletions library/src/main/java/com/r0adkll/slidr/widget/SliderPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewGroupCompat;
import android.support.v4.widget.ViewDragHelper;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;

import com.r0adkll.slidr.model.SlidrConfig;
import com.r0adkll.slidr.model.SlidrPosition;

import static com.r0adkll.slidr.model.SlidrPosition.*;

/**
Expand All @@ -43,6 +42,7 @@ public class SliderPanel extends FrameLayout {
*/

private int mScreenWidth;
private int mScreenHeight;
private View mDimView;
private View mDecorView;
private ViewDragHelper mDragHelper;
Expand Down Expand Up @@ -118,6 +118,7 @@ private void init(){
mDragHelper.setMinVelocity(minVel);
mDragHelper.setEdgeTrackingEnabled(position);


ViewGroupCompat.setMotionEventSplittingEnabled(this, false);

// Setup the dimmer view
Expand All @@ -128,6 +129,18 @@ private void init(){
// Add the dimmer view to the layout
addView(mDimView);

/*
* This is so we can get the height of the view and
* ignore the system navigation that would be included if we
* retrieved this value from the DisplayMetrics
*/
post(new Runnable() {
@Override
public void run() {
mScreenHeight = getHeight();
}
});

}

/**********************************************************
Expand Down Expand Up @@ -182,6 +195,8 @@ public void unlock(){

/**
* The drag helper callback interface for the Left position
*
*
*/
private ViewDragHelper.Callback mLeftCallback = new ViewDragHelper.Callback() {

Expand Down Expand Up @@ -248,6 +263,11 @@ public void onViewDragStateChanged(int state) {

};

/**
* The drag helper callbacks for dragging the slidr attachment from the right of the screen
*
*
*/
private ViewDragHelper.Callback mRightCallback = new ViewDragHelper.Callback() {
@Override
public boolean tryCaptureView(View child, int pointerId) {
Expand Down Expand Up @@ -311,17 +331,136 @@ public void onViewDragStateChanged(int state) {
}
};

/**
* The drag helper callbacks for dragging the slidr attachment from the top of the screen
*
*/
private ViewDragHelper.Callback mTopCallback = new ViewDragHelper.Callback() {
@Override
public boolean tryCaptureView(View child, int pointerId) {
return false;
return child.getId() == mDecorView.getId();
}

@Override
public int clampViewPositionVertical(View child, int top, int dy) {
return clamp(top, 0, mScreenHeight);
}

@Override
public int getViewVerticalDragRange(View child) {
return mScreenHeight;
}

@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
super.onViewReleased(releasedChild, xvel, yvel);

final int height = getHeight();
float offset = height - releasedChild.getTop();
int top = yvel < 0 || yvel == 0 && offset > 0.5f ? 0 : mScreenHeight;

mDragHelper.settleCapturedViewAt(releasedChild.getLeft(), top);
invalidate();
}

@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
super.onViewPositionChanged(changedView, left, top, dx, dy);
float percent = 1f - ((float)Math.abs(top) / (float)mScreenHeight);

if(mListener != null) mListener.onSlideChange(percent);

// Update the dimmer alpha
float alpha = percent * MAX_DIM_ALPHA;
mDimView.setAlpha(alpha);
}

@Override
public void onViewDragStateChanged(int state) {
super.onViewDragStateChanged(state);
switch (state){
case ViewDragHelper.STATE_IDLE:
if(mDecorView.getTop() == 0){
// State Open
if(mListener != null) mListener.onOpened();
}else{
// State Closed
if(mListener != null) mListener.onClosed();
}
break;
case ViewDragHelper.STATE_DRAGGING:

break;
case ViewDragHelper.STATE_SETTLING:

break;
}
}
};

/**
* The drag helper callbacks for dragging the slidr attachment from the bottom of hte screen
*/
private ViewDragHelper.Callback mBottomCallback = new ViewDragHelper.Callback() {
@Override
public boolean tryCaptureView(View child, int pointerId) {
return false;
return child.getId() == mDecorView.getId();
}

@Override
public int clampViewPositionVertical(View child, int top, int dy) {
return clamp(top, -mScreenHeight, 0);
}

@Override
public int getViewVerticalDragRange(View child) {
return mScreenHeight;
}

@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
super.onViewReleased(releasedChild, xvel, yvel);

final int height = getHeight();
float offset = height - releasedChild.getTop();
int top = yvel > 0 || yvel == 0 && offset < (mScreenHeight-0.5f) ? 0 : -mScreenHeight;

mDragHelper.settleCapturedViewAt(releasedChild.getLeft(), top);
invalidate();
}

@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
super.onViewPositionChanged(changedView, left, top, dx, dy);
float percent = 1f - ((float)Math.abs(top) / (float)mScreenHeight);

if(mListener != null) mListener.onSlideChange(percent);

// Update the dimmer alpha
float alpha = percent * MAX_DIM_ALPHA;
mDimView.setAlpha(alpha);
}

@Override
public void onViewDragStateChanged(int state) {
super.onViewDragStateChanged(state);
switch (state){
case ViewDragHelper.STATE_IDLE:
if(mDecorView.getTop() == 0){
// State Open
if(mListener != null) mListener.onOpened();
}else{
// State Closed
if(mListener != null) mListener.onClosed();
}
break;
case ViewDragHelper.STATE_DRAGGING:

break;
case ViewDragHelper.STATE_SETTLING:

break;
}
}
};

Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="slidable_panel" type="id" />
<item name="slidable_content" type="id" />
</resources>

0 comments on commit 4dd344c

Please sign in to comment.