Skip to content

Commit

Permalink
Begun ground work on letting the developer submit a Configuration on …
Browse files Browse the repository at this point in the history
…how the sliding mechanism works, such as it's touch size, slide start position (left, right, top, bottom), the status bar colors, and other small tweaks.

reference to r0adkll#1
  • Loading branch information
r0adkll committed Jan 13, 2015
1 parent 8179f23 commit 37d4179
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 11 deletions.
Binary file modified build/intermediates/model_data.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_NAME=2.0.1
VERSION_CODE=4
VERSION_NAME=2.0.2-SNAPSHOT
VERSION_CODE=5
GROUP=com.r0adkll

POM_DESCRIPTION=A simple activity that adds sliding functionality to activities to swipe them away
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 4
versionName "2.0.1"
versionCode 5
versionName "2.0.2"
}

compileOptions {
Expand Down
75 changes: 73 additions & 2 deletions library/src/main/java/com/r0adkll/slidr/Slidr.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.view.View;
import android.view.ViewGroup;

import com.r0adkll.slidr.model.SlidrConfig;
import com.r0adkll.slidr.model.SlidrInterface;
import com.r0adkll.slidr.widget.SliderPanel;

/**
Expand All @@ -23,7 +25,7 @@ public class Slidr {
* Attach a slideable mechanism to an activity that adds the slide to dismiss functionality
*
* @param activity the activity to attach the slider to
* @return a {@link com.r0adkll.slidr.SlidrInterface} that allows
* @return a {@link com.r0adkll.slidr.model.SlidrInterface} that allows
* the user to lock/unlock the sliding mechanism for whatever purpose.
*/
public static SlidrInterface attach(Activity activity){
Expand All @@ -39,7 +41,7 @@ public static SlidrInterface attach(Activity activity){
* @param statusBarColor2 the primaryDark status bar color of the activity this is attaching to that will transition
* back to the statusBarColor1 color
*
* @return a {@link com.r0adkll.slidr.SlidrInterface} that allows
* @return a {@link com.r0adkll.slidr.model.SlidrInterface} that allows
* the user to lock/unlock the sliding mechanism for whatever purpose.
*/
public static SlidrInterface attach(final Activity activity, final int statusBarColor1, final int statusBarColor2){
Expand Down Expand Up @@ -98,4 +100,73 @@ public void unlock() {
return slidrInterface;
}

/**
* Attach a slider mechanism to an activity based on the passed {@link com.r0adkll.slidr.model.SlidrConfig}
*
* @param activity the activity to attach the slider to
* @param config the slider configuration to make
* @return a {@link com.r0adkll.slidr.model.SlidrInterface} that allows
* the user to lock/unlock the sliding mechanism for whatever purpose.
*/
public static SlidrInterface attach(final Activity activity, final SlidrConfig config){

// Hijack the decorview
ViewGroup decorView = (ViewGroup)activity.getWindow().getDecorView();
View oldScreen = decorView.getChildAt(0);
decorView.removeViewAt(0);

// Setup the slider panel and attach it to the decor
final SliderPanel panel = new SliderPanel(activity, oldScreen);
panel.setId(R.id.slidable_panel);
panel.addView(oldScreen);
decorView.addView(panel, 0);

// Set the panel slide listener for when it becomes closed or opened
panel.setOnPanelSlideListener(new SliderPanel.OnPanelSlideListener() {

private final ArgbEvaluator mEvaluator = new ArgbEvaluator();

@Override
public void onClosed() {
activity.finish();
activity.overridePendingTransition(0, 0);
}

@Override
public void onOpened() {}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onSlideChange(float percent) {
// Interpolate the statusbar color
// TODO: Add support for KitKat
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
config.areStatusBarColorsValid()){

int newColor = (int) mEvaluator.evaluate(percent, config.getPrimaryColor(),
config.getSecondaryColor());

activity.getWindow().setStatusBarColor(newColor);
}
}
});

// Setup the lock interface
SlidrInterface slidrInterface = new SlidrInterface() {
@Override
public void lock() {
panel.lock();
}

@Override
public void unlock() {
panel.unlock();
}
};

// Return the lock interface
return slidrInterface;

}

}
124 changes: 124 additions & 0 deletions library/src/main/java/com/r0adkll/slidr/model/SlidrConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.r0adkll.slidr.model;

/**
* This class contains the configuration information for all the options available in
* this library
*
* Created by r0adkll on 1/12/15.
*/
public class SlidrConfig {

private int colorPrimary = -1;
private int colorSecondary = -1;
private SlidrPosition position = SlidrPosition.LEFT;
private float touchSize = -1f;
private float sensitivity = 1f;

/**
* Hidden Constructor
* Use the builder pattern
*/
private SlidrConfig(){}

/**
* Get the primary color that the slider will interpolate. That is this color is the color
* of the status bar of the Activity you are returning to
*
* @return the primary status bar color
*/
public int getPrimaryColor(){
return colorPrimary;
}

/**
* Get the secondary color that the slider will interpolatel That is the color of the Activity
* that you are making slidable
*
* @return the secondary status bar color
*/
public int getSecondaryColor(){
return colorSecondary;
}

/**
* Get the position of the slidable mechanism for this configuration. This is the position on
* the screen that the user can swipe the activity away from
*
* @return the slider position
*/
public SlidrPosition getPosition(){
return position;
}

/**
* Get the touch 'width' to be used in the gesture detection. This value should incorporate with
* the device's touch slop
*
* @return the touch area size
*/
public float getTouchSize(){
return touchSize;
}

/**
* Get the touch sensitivity set in the {@link android.support.v4.widget.ViewDragHelper} when
* creating it.
*
* @return the touch sensitivity
*/
public float getSensitivity(){
return sensitivity;
}

/**
* Return whether or not the set status bar colors are valid
* @return
*/
public boolean areStatusBarColorsValid(){
return colorPrimary != -1 && colorSecondary != -1;
}

/**
* The Builder for this configuration class. This is the only way to create a
* configuration
*/
public static class Builder{

private SlidrConfig config;

public Builder(){
config = new SlidrConfig();
}

public Builder setPrimaryColor(int color){
config.colorPrimary = color;
return this;
}

public Builder setSecondaryColor(int color){
config.colorSecondary = color;
return this;
}

public Builder setPosition(SlidrPosition position){
config.position = position;
return this;
}

public Builder setTouchSize(float size){
config.touchSize = size;
return this;
}

public Builder setSensitivity(float sensitivity){
config.sensitivity = sensitivity;
return this;
}

public SlidrConfig build(){
return config;
}

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.r0adkll.slidr;
package com.r0adkll.slidr.model;

/**
* Created by r0adkll on 1/9/15.
Expand Down
11 changes: 11 additions & 0 deletions library/src/main/java/com/r0adkll/slidr/model/SlidrPosition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.r0adkll.slidr.model;

/**
* Created by r0adkll on 1/12/15.
*/
public enum SlidrPosition {
LEFT,
RIGHT,
TOP,
BOTTOM;
}
73 changes: 69 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 @@ -14,6 +14,11 @@
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.*;

/**
* Project: PilotPass
* Package: com.ftinc.mariner.pilotpass.widgets
Expand Down Expand Up @@ -44,6 +49,8 @@ public class SliderPanel extends FrameLayout {
private OnPanelSlideListener mListener;
private boolean mIsLocked = false;

private SlidrConfig mConfig;

/**
* Constructor
*
Expand All @@ -52,6 +59,14 @@ public class SliderPanel extends FrameLayout {
public SliderPanel(Context context, View decorView) {
super(context);
mDecorView = decorView;
mConfig = new SlidrConfig.Builder().build();
init();
}

public SliderPanel(Context context, View decorView, SlidrConfig config){
super(context);
mDecorView = decorView;
mConfig = config;
init();
}

Expand All @@ -65,16 +80,43 @@ public void setOnPanelSlideListener(OnPanelSlideListener listener){

/**
* Initialize the slider panel
*
* TODO: Based on SlidrPosition configure the ViewDragHelper to the appropriate position.
*
*/
private void init(){
mScreenWidth = getResources().getDisplayMetrics().widthPixels;

final float density = getResources().getDisplayMetrics().density;
final float minVel = MIN_FLING_VELOCITY * density;

mDragHelper = ViewDragHelper.create(this, 1f, mCallback);
ViewDragHelper.Callback callback;
int position;
switch (mConfig.getPosition()){
case LEFT:
callback = mLeftCallback;
position = ViewDragHelper.EDGE_LEFT;
break;
case RIGHT:
callback = mRightCallback;
position = ViewDragHelper.EDGE_RIGHT;
break;
case TOP:
callback = mTopCallback;
position = ViewDragHelper.EDGE_TOP;
break;
case BOTTOM:
callback = mBottomCallback;
position = ViewDragHelper.EDGE_BOTTOM;
break;
default:
callback = mLeftCallback;
position = ViewDragHelper.EDGE_LEFT;
}

mDragHelper = ViewDragHelper.create(this, mConfig.getSensitivity(), callback);
mDragHelper.setMinVelocity(minVel);
mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
mDragHelper.setEdgeTrackingEnabled(position);

ViewGroupCompat.setMotionEventSplittingEnabled(this, false);

Expand Down Expand Up @@ -139,9 +181,9 @@ public void unlock(){


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

@Override
public boolean tryCaptureView(View child, int pointerId) {
Expand Down Expand Up @@ -204,6 +246,29 @@ public void onViewDragStateChanged(int state) {
}
}



};

private ViewDragHelper.Callback mRightCallback = new ViewDragHelper.Callback() {
@Override
public boolean tryCaptureView(View child, int pointerId) {
return false;
}
};

private ViewDragHelper.Callback mTopCallback = new ViewDragHelper.Callback() {
@Override
public boolean tryCaptureView(View child, int pointerId) {
return false;
}
};

private ViewDragHelper.Callback mBottomCallback = new ViewDragHelper.Callback() {
@Override
public boolean tryCaptureView(View child, int pointerId) {
return false;
}
};


Expand Down

0 comments on commit 37d4179

Please sign in to comment.