Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Added the ability to swipe the Slidr from the right
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
r0adkll committed Feb 10, 2015
1 parent 1c0dcec commit 9857bbc
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 69 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

local.properties
Slidr.iml
.idea/libraries
.idea/encodings.xml
.idea/compiler.xml
.idea/modules.xml
.idea/misc.xml
.idea/vcs.xml
build
6 changes: 2 additions & 4 deletions .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: 1 addition & 3 deletions .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: 2 additions & 2 deletions .idea/libraries/support_annotations_21_0_3.xml

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

10 changes: 4 additions & 6 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.

11 changes: 0 additions & 11 deletions .idea/libraries/timber_2_5_1_SNAPSHOT.xml

This file was deleted.

21 changes: 0 additions & 21 deletions SlidableActivity.iml

This file was deleted.

Binary file removed build/intermediates/model_data.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/build
/build
8 changes: 5 additions & 3 deletions example/example.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="Slidr" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand All @@ -9,6 +9,7 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
Expand All @@ -24,6 +25,7 @@
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
Expand Down Expand Up @@ -81,15 +83,15 @@
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform (1)" jdkType="Android SDK" />
<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="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="butterknife-6.0.0" level="project" />
<orderEntry type="library" exported="" name="timber-2.5.1-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="picasso-2.4.0" level="project" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.r0adkll.deadskunk.views.AspectRatioImageView;
import com.r0adkll.slidr.Slidr;
import com.r0adkll.slidr.example.model.AndroidOS;
import com.r0adkll.slidr.model.SlidrConfig;
import com.r0adkll.slidr.model.SlidrPosition;
import com.squareup.picasso.Picasso;

import butterknife.ButterKnife;
Expand Down Expand Up @@ -44,22 +46,35 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewer);
ButterKnife.inject(this);

// Get the status bar colors to interpolate between
int primary = getResources().getColor(R.color.primaryDark);
int secondary = getResources().getColor(R.color.accent);
Slidr.attach(this, primary, secondary);

// Build the slidr config
SlidrConfig config = new SlidrConfig.Builder()
.primaryColor(primary)
.secondaryColor(secondary)
.position(SlidrPosition.RIGHT)
.build();

// Attach the Slidr Mechanism to this activity
Slidr.attach(this, config);

setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mOS = getIntent().getParcelableExtra(EXTRA_OS);
if(savedInstanceState != null) mOS = savedInstanceState.getParcelable(EXTRA_OS);

// Set layout contents
mTitle.setText(mOS.name);
mDescription.setText(mOS.description);
mDate.setText(String.valueOf(mOS.year));
mVersion.setText(mOS.version);
mSdk.setText(String.valueOf(mOS.sdk_int));

// Load header image
Picasso.with(this)
.load(mOS.image_url)
.into(mCover);
Expand Down
9 changes: 4 additions & 5 deletions library/library.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="Slidr" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand All @@ -9,6 +9,7 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
Expand All @@ -25,6 +26,7 @@
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
Expand Down Expand Up @@ -60,7 +62,6 @@
<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 @@ -80,12 +81,10 @@
<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 (1)" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/r0adkll/slidr/Slidr.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static SlidrInterface attach(final Activity activity, final SlidrConfig c
decorView.removeViewAt(0);

// Setup the slider panel and attach it to the decor
final SliderPanel panel = new SliderPanel(activity, oldScreen);
final SliderPanel panel = new SliderPanel(activity, oldScreen, config);
panel.setId(R.id.slidable_panel);
panel.addView(oldScreen);
decorView.addView(panel, 0);
Expand Down
10 changes: 5 additions & 5 deletions library/src/main/java/com/r0adkll/slidr/model/SlidrConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,27 @@ public Builder(){
config = new SlidrConfig();
}

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

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

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

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

public Builder setSensitivity(float sensitivity){
public Builder sensitivity(float sensitivity){
config.sensitivity = sensitivity;
return this;
}
Expand Down
62 changes: 58 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 @@ -215,7 +215,7 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) {
@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
super.onViewPositionChanged(changedView, left, top, dx, dy);
float percent = 1 - ((float)left / (float)mScreenWidth);
float percent = 1f - ((float)left / (float)mScreenWidth);

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

Expand Down Expand Up @@ -246,14 +246,68 @@ public void onViewDragStateChanged(int state) {
}
}



};

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

@Override
public int clampViewPositionHorizontal(View child, int left, int dx) {
return clamp(left, -mScreenWidth, 0);
}

@Override
public int getViewHorizontalDragRange(View child) {
return mScreenWidth;
}

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

final int width = getWidth();
float offset = width + releasedChild.getLeft();
int left = xvel > 0 || xvel == 0 && offset < (mScreenWidth - 0.5f) ? 0 : -mScreenWidth;

mDragHelper.settleCapturedViewAt(left, releasedChild.getTop());
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(left) / (float)mScreenWidth);

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.getLeft() == 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
4 changes: 2 additions & 2 deletions local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Fri Jan 09 23:44:30 EST 2015
sdk.dir=/Users/r0adkll/Documents/Developer/android-sdk
#Tue Feb 10 09:52:57 EST 2015
sdk.dir=/Users/drew.heavner/android-sdk

0 comments on commit 9857bbc

Please sign in to comment.