Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ppamorim committed Apr 22, 2015
2 parents a2278f7 + e07593e commit 6d67bbd
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 94 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: android

android:
components:
- build-tools-21.1.2
- android-21
- build-tools-22.0.0
- android-22

script:
./gradlew checkstyle build
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
[![Join the chat at https://gitter.im/ppamorim/Dragger](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ppamorim/Dragger?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

The library was created in order to provide new animations for activities on Android.
Using the ViewDragHelper class, it was possible to create smooth animations and that's allow a full controls of the view for user.
Using the ViewDragHelper class, it is possible to create smooth animations that allow full control of the view by the user.

This new component has been created using some concepts described on [Flavien Laurent Blog][1] and [Denevell Blog][2].

This library can works on API 10 (but not tested yet).
This library should work on API 10 (but not tested yet).

![Demo 1][11]

Usage
-----


You can use this library like a view, you need just do it:
You can use this library like a view, you just need to do the following:

* 1. Add ''DraggerView'' view on your root layout and add two layouts inside this.
You can add a shadow view if you want(the first one) and it need to be invisible.
* 1. Add ''DraggerView'' view to your root layout and add two layouts inside it.
You can add a shadow view if you want (the first one) and it needs to be invisible.

```xml
<com.github.library.DraggerView
<com.github.ppamorim.library.DraggerView
android:layout_width="match_parent"
android:layout_height="match_parent"
dragger_layout:drag_view_id="@+id/drag_view"
Expand All @@ -43,10 +43,10 @@ You can add a shadow view if you want(the first one) and it need to be invisible
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</com.github.library.DraggerView>
</com.github.ppamorim.library.DraggerView>
```

In your ''styles'' file, you need config like this:
In your ''styles'' file, you need a config like this:

```xml
<style name="YourTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Expand All @@ -66,7 +66,7 @@ And your ''manifest'':
android:theme="@style/YourTheme"/>
```

Or, if you need to be fast:
Or, if you need it to be fast:

```java
public class YourActivity extends DraggerActivity {
Expand All @@ -89,9 +89,12 @@ Sample
Import dependency
--------------------------------

This library uses nineoldandroids:2.4.0 and appcompat-v7:21.0.3, you have to provide this dependencies from your local artifact repository or from maven central repository.
This library uses nineoldandroids:2.4.0 and appcompat-v7:21.0.3.

I'll release a day on MavenCentral, I haven't much time and had to deploy on jitPack
But why not add in MavenCentral?
Because it is so much bureaucratic.

JitPack is there and is the future!

Into your build.gradle:

Expand All @@ -104,14 +107,15 @@ repositories {
}
dependencies {
compile 'com.github.ppamorim:Dragger:2324e5f2a5'
compile 'com.github.ppamorim:Dragger:v1.0'
}
```

Contributors
------------

* [Pedro Paulo de Amorim][3]
* [Falkirks][12]

This was only possible because [Pedro Vicente Gómez Sánchez][4] helped me and I am very grateful for that! Thank you. :)

Expand All @@ -132,7 +136,6 @@ Libraries used on the sample project

* [Butterknife][5]
* [NineOldAndroids][6]
* [Picasso][7]

License
-------
Expand All @@ -159,4 +162,5 @@ License
[6]: https://github.com/JakeWharton/NineOldAndroids/
[7]: https://github.com/square/picasso
[10]: ./art/dragger.png
[11]: http://i.imgur.com/goPWgq1.gif
[11]: http://i.imgur.com/goPWgq1.gif
[12]: https://github.com/Falkirks
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
"https://www.puppycrawl.com/dtds/configuration_1_2.dtd">

<!-- THIS CHECKSYTLE CONFIGURATION IS SIMILAR TO THE ONE USED BY SQUARE INC. IF YOU WANT TO
CONFIGURE YOUR IDE TO USE THIS CHECKSTYLE TAKE A LOOK AT https://github.com/square/java-code-styles-->
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VERSION_NAME=0.1
VERSION_CODE=1
GROUP=com.ppamorim.dragger
GROUP=com.github.dragger

POM_DESCRIPTION=
POM_URL=https://github.com/ppamorim/Dragger
Expand All @@ -13,7 +13,7 @@ POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=ppamorim
POM_DEVELOPER_NAME=Pedro Paulo de Amorim

ANDROID_BUILD_TOOLS_VERSION=21.1.2
ANDROID_COMPILE_SDK_VERSION=21
ANDROID_TARGET_SDK_VERSION=21
ANDROID_MIN_SDK=8
ANDROID_BUILD_TOOLS_VERSION=22.0.1
ANDROID_COMPILE_SDK_VERSION=22
ANDROID_TARGET_SDK_VERSION=22
ANDROID_MIN_SDK=10
40 changes: 0 additions & 40 deletions library/.gitignore

This file was deleted.

17 changes: 0 additions & 17 deletions library/proguard-rules.pro

This file was deleted.

113 changes: 98 additions & 15 deletions library/src/main/java/com/github/ppamorim/library/DraggerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.ListView;
import com.nineoldandroids.view.ViewHelper;

/**
Expand All @@ -49,6 +51,7 @@ public class DraggerView extends FrameLayout {
private static final int INVALID_POINTER = -1;

private boolean canFinish = false;
private boolean canSlide = true;
private int activePointerId = INVALID_POINTER;
private float verticalDragRange;
private float horizontalDragRange;
Expand Down Expand Up @@ -111,7 +114,7 @@ public DraggerView(Context context, AttributeSet attrs, int defStyle) {
}

@Override public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!isEnabled()) {
if (!isEnabled() || isListOnTop()) {
return false;
}
final int action = MotionEventCompat.getActionMasked(ev);
Expand Down Expand Up @@ -167,6 +170,82 @@ private void setHorizontalDragRange(float horizontalDragRange) {
this.horizontalDragRange = horizontalDragRange;
}

public void setListViewPosition(final ListView listView) {
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override public void onScrollStateChanged(AbsListView view, int scrollState) {

}

@Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {

switch (dragPosition) {
case LEFT:
//parentSize = dragView.getWidth();
//viewAxisPosition = -ViewHelper.getX(dragView) + (parentSize * dragLimit);
break;
case RIGHT:
//parentSize = dragView.getWidth();
//viewAxisPosition = ViewHelper.getX(dragView) + (parentSize * dragLimit);
break;
case TOP:
default:
if(firstVisibleItem > 0) {
return;
}
setCanSlide(canScrollUp(listView));
break;
case BOTTOM:
if(firstVisibleItem < totalItemCount) {
return;
}
setCanSlide(canScrollDown(listView));
break;
}

}
});

}

public boolean isListOnTop() {
return canSlide;
}

public void setCanSlide(boolean canSlide) {
this.canSlide = canSlide;
}

public boolean canScrollUp(View view) {
if (android.os.Build.VERSION.SDK_INT < 14) {
if (view instanceof AbsListView) {
final AbsListView absListView = (AbsListView) view;
return absListView.getChildCount() > 0
&& (absListView.getFirstVisiblePosition() > 0 || absListView
.getChildAt(0).getTop() < absListView.getPaddingTop());
} else {
return view.getScrollY() > 0;
}
} else {
return ViewCompat.canScrollVertically(view, -1);
}
}

public boolean canScrollDown(View view) {
if (android.os.Build.VERSION.SDK_INT < 14) {
if (view instanceof AbsListView) {
final AbsListView absListView = (AbsListView) view;
return absListView.getChildCount() > 0
&& (absListView.getFirstVisiblePosition() > 0 || absListView
.getChildAt(0).getBottom() < absListView.getPaddingBottom());
} else {
return view.getScrollY() > 0;
}
} else {
return ViewCompat.canScrollVertically(view, -1);
}
}

public float getDragLimit() {
return dragLimit;
}
Expand Down Expand Up @@ -271,20 +350,24 @@ private void openActivity() {
}

public void closeActivity() {
switch (dragPosition) {
case LEFT:
closeFromCenterToLeft();
break;
case RIGHT:
closeFromCenterToRight();
break;
case TOP:
default:
closeFromCenterToBottom();
break;
case BOTTOM:
closeFromCenterToTop();
break;
if(dragPosition != null) {
switch (dragPosition) {
case LEFT:
closeFromCenterToLeft();
break;
case RIGHT:
closeFromCenterToRight();
break;
case TOP:
default:
closeFromCenterToBottom();
break;
case BOTTOM:
closeFromCenterToTop();
break;
}
} else {
throw new IllegalStateException("dragPosition is null");
}
}

Expand Down

0 comments on commit 6d67bbd

Please sign in to comment.