Skip to content

Commit

Permalink
Integrating a listener in the config to get callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
r0adkll committed Feb 24, 2015
1 parent ba73893 commit a359d1c
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .idea/libraries/cardview_v7_21_0_3.xml

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

4 changes: 3 additions & 1 deletion .idea/libraries/recyclerview_v7_21_0_3.xml

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

4 changes: 3 additions & 1 deletion .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.

2 changes: 1 addition & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repositories {

android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "com.r0adkll.slidr.example"
Expand Down
2 changes: 1 addition & 1 deletion example/example.iml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
<orderEntry type="library" exported="" name="timber-2.5.2-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="deadskunk-1.0.4-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="timber-2.7.2-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="butterknife-6.0.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-21.0.3" level="project" />
Expand Down
3 changes: 3 additions & 0 deletions library/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand All @@ -81,7 +82,9 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
Expand Down
14 changes: 13 additions & 1 deletion library/src/main/java/com/r0adkll/slidr/Slidr.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,20 @@ public static SlidrInterface attach(final Activity activity, final SlidrConfig c

@Override
public void onClosed() {
if(config.getListener() != null){
config.getListener().onSlideClosed();
}

activity.finish();
activity.overridePendingTransition(0, 0);
}

@Override
public void onOpened() {}
public void onOpened() {
if(config.getListener() != null){
config.getListener().onSlideOpened();
}
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
Expand All @@ -150,6 +158,10 @@ public void onSlideChange(float percent) {

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

if(config.getListener() != null){
config.getListener().onSlideChange(percent);
}
}
});

Expand Down
10 changes: 10 additions & 0 deletions library/src/main/java/com/r0adkll/slidr/model/SlidrConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SlidrConfig {
private SlidrPosition position = SlidrPosition.LEFT;
private float touchSize = -1f;
private float sensitivity = 1f;
private SlidrListener listener;

/**
* Hidden Constructor
Expand Down Expand Up @@ -70,6 +71,10 @@ public float getSensitivity(){
return sensitivity;
}

public SlidrListener getListener(){
return listener;
}

/**
* Return whether or not the set status bar colors are valid
* @return
Expand Down Expand Up @@ -115,6 +120,11 @@ public Builder sensitivity(float sensitivity){
return this;
}

public Builder listener(SlidrListener listener){
config.listener = listener;
return this;
}

public SlidrConfig build(){
return config;
}
Expand Down
19 changes: 19 additions & 0 deletions library/src/main/java/com/r0adkll/slidr/model/SlidrListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.r0adkll.slidr.model;

/**
* This listener interface is for receiving events from the sliding panel such as state changes
* and slide progress
*
* Project: Slidr
* Package: com.r0adkll.slidr.model
* Created by drew.heavner on 2/24/15.
*/
public interface SlidrListener {

public void onSlideChange(float percent);

public void onSlideOpened();

public void onSlideClosed();

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

/**
* Project: Slidr
* Package: com.r0adkll.slidr.model
* Created by drew.heavner on 2/24/15.
*/
public class SlidrListenerAdapter implements SlidrListener{
@Override
public void onSlideChange(float percent) {

}

@Override
public void onSlideOpened() {

}

@Override
public void onSlideClosed() {

}
}

0 comments on commit a359d1c

Please sign in to comment.