Skip to content

Commit

Permalink
Release 0.4.0: animations and convenience
Browse files Browse the repository at this point in the history
Changelog covers major details of this release. Important ones
include remove and drop animations, and a DragSortController
feature that gives you click-to-remove skills. Oh yeah.

Maven build process has been somewhat streamlined.
  • Loading branch information
bauerca committed Nov 16, 2012
1 parent 05460d1 commit a645bab
Show file tree
Hide file tree
Showing 21 changed files with 708 additions and 137 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Changelog
=========

0.4.0
-----

* Implement remove and drop animations.
* Update on(Intercept)TouchEvent to make sure DSLV ignores
touch events during remove/drop animations.
* Add `removeItem(int)` method to DragSortListView, which allows item
removal outside drag-sorting and animates the removal process.
* Add click-to-remove convenience to DragSortController.
* Fix #51: NullPointerException when a null ListAdapter is passed to
`setAdapter(ListAdapter)`.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ http://bauerca.github.com/drag-sort-listview).
**Nov. 11, 2012**: Mavenized.
Thanks to [Andreas Schildbach (Goonie)](https://github.com/Goonie)!

**Nov. 15, 2012**: Smooth operation! Drops and removals are animated.
Also, DragSortController now provides a convenience
click-to-remove feature (see [XML attrs](https://github.com/bauerca/drag-sort-listview#xml-layout-declaration)
and [RemoveListener](https://github.com/bauerca/drag-sort-listview#dragsortlistviewremovelistener)
sections).

Overview
--------

Expand Down Expand Up @@ -88,7 +94,7 @@ ListView attributes) are given below. Read each bullet as
#### XML attributes

* `collapsed_height`: (dimension, 1px) Height of placeholder at original
drag position.
drag position. Cannot be zero.
* `drag_scroll_start`: (float, 0.3) Start of drag-scroll regions
(defined by a
fraction of the total DSLV height; i.e. between 0 and 1).
Expand All @@ -100,6 +106,12 @@ default linear drag-scroll profile. Units of pixels/millisecond.
underneath floating View. A value
of 0 means a shuffle animation is always in progress, whereas a value
of 1 means items snap from position to position without animation.
* `drop_animation_duration`: (int, 150) Drop animation smoothly centers
the floating View over the drop slot before destroying it. Duration
in milliseconds.
* `remove_animation_duration`: (int, 150) Remove animation smoothly
collapses the empty slot when an item is removed. Duration
in milliseconds.
* `track_drag_sort`: (bool, false) Debugging option; explained below.
* `use_default_controller`: (bool, true) Have DSLV create a
DragSortController instance and pass the following xml attributes
Expand Down Expand Up @@ -129,12 +141,17 @@ of 1 means items snap from position to position without animation.
of the `remove_mode` options below.
* `remove_mode`: (enum, "flingRight") Sets the gesture for removing the
dragged item.
+ "clickRemove": Click on item child View with id `click_remove_id`.
+ "flingRight": Fling to the right; get outta here!
+ "flingLeft": Fling to the left; sayonara sucker!
+ "slideRight": Floating View fades as you slide your finger
to the right; lifting while faded removes item.
+ "slideLeft": Floating View fades as you slide your finger
to the right; lifting while faded removes item.
* `click_remove_id`: (id, 0) Android resource id that points to a
child View of a list item. When `remove_mode="clickRemove"` and
`remove_enabled="true"`, a click on this child View removes the
containing item. This attr is used by DragSortController.

### Listeners

Expand Down Expand Up @@ -192,6 +209,9 @@ the mapping from your data (e.g. in a Cursor) to your ListAdapter
should henceforth neglect the item previously pointed to by `which`.
Whether you actually remove the data or not is up to you.

Item removal can now happen outside of a drag event. The method
`DragSortListView.removeItem(int position)` can be called at any time.

#### DragSortListView.DragListener

The callback in the DragListener is
Expand Down
8 changes: 5 additions & 3 deletions demo/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobeta.android.demodslv"
android:versionCode="1"
android:versionName="1.0">
android:versionName="0.4.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="@string/app_name" >
<application android:label="@string/app_name"
android:icon="@drawable/dslv_launcher" >
<activity android:name="Launcher"
android:icon="@drawable/dslv_launcher"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -24,6 +26,6 @@
<activity android:name="Sections"
android:label="Sections" />
<activity android:name="CursorDSLV"
android:label="DB backed" />
android:label="Cursor-backed" />
</application>
</manifest>
33 changes: 11 additions & 22 deletions demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,33 @@ Copyright 2012 Andreas Schildbach
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mobeta.android.demodslv</groupId>
<artifactId>drag-sort-listview-demo</artifactId>
<packaging>apk</packaging>
<version>0.3.0-SNAPSHOT</version>

<parent>
<groupId>com.mobeta.android.dslv</groupId>
<artifactId>parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>com.mobeta.android.demodslv</groupId>
<artifactId>drag-sort-listview-demo</artifactId>
<packaging>apk</packaging>
<version>0.4.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.mobeta.android.dslv</groupId>
<artifactId>drag-sort-listview</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>${project.version}</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.1_r1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>
</dependencies>

Expand All @@ -57,20 +55,11 @@ Copyright 2012 Andreas Schildbach
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.2</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
</plugin>
</plugins>
</pluginManagement>

</build>
</project>
Binary file added demo/res/drawable-hdpi/delete_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/res/drawable-hdpi/dslv_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/res/drawable-mdpi/dslv_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion demo/res/layout/cursor_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
dslv:drag_start_mode="onDown"
dslv:drag_handle_id="@id/drag_handle"
dslv:remove_enabled="true"
dslv:remove_mode="flingLeft" />
dslv:remove_mode="clickRemove"
dslv:click_remove_id="@id/click_remove" />
27 changes: 27 additions & 0 deletions demo/res/layout/list_item_click_remove.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="@dimen/item_height"
android:orientation="horizontal">
<ImageView
android:id="@id/drag_handle"
android:background="@drawable/drag"
android:layout_width="wrap_content"
android:layout_height="@dimen/item_height"
android:layout_weight="0" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="@dimen/item_height"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center_vertical"
android:paddingLeft="8dp" />
<ImageView
android:id="@id/click_remove"
android:background="@drawable/delete_x"
android:layout_width="@dimen/item_height"
android:layout_height="@dimen/item_height"
android:layout_weight="0" />
</LinearLayout>
1 change: 1 addition & 0 deletions demo/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 type="id" name="drag_handle" />
<item type="id" name="click_remove" />
</resources>
3 changes: 2 additions & 1 deletion demo/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">DemoDSLV</string>
<string name="app_name">Drag-Sort Demos</string>
<string-array name="activity_titles">
<item>Basic usage playground</item>
<item>Heteroheight</item>
Expand Down Expand Up @@ -47,6 +47,7 @@
<string name="add_header">Add header</string>
<string name="add_footer">Add footer</string>
<string-array name="remove_mode_labels">
<item>Click remove</item>
<item>Fling right</item>
<item>Fling left</item>
<item>Slide right</item>
Expand Down
5 changes: 5 additions & 0 deletions demo/src/com/mobeta/android/demodslv/ArbItemSizeDSLV.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.ListView;
import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -42,6 +43,10 @@ public void remove(int which) {
}
};

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
((DragSortListView) l).removeItem(position - l.getHeaderViewsCount());
}

/** Called when the activity is first created. */
@Override
Expand Down
8 changes: 7 additions & 1 deletion demo/src/com/mobeta/android/demodslv/CursorDSLV.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void onCreate(Bundle savedInstanceState) {
String[] cols = {"name"};
int[] ids = {R.id.text};
adapter = new SimpleDragSortCursorAdapter(this,
R.layout.list_item_handle_right, null, cols, ids, 0);
R.layout.list_item_click_remove, null, cols, ids, 0);

DragSortListView dslv = (DragSortListView) findViewById(android.R.id.list);
dslv.setAdapter(adapter);
Expand Down Expand Up @@ -108,4 +108,10 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
public void onLoaderReset(Loader<Cursor> loader) {
adapter.changeCursor(null);
}

@Override
public void onDestroy() {
super.onDestroy();
mOpenHelper.close();
}
}
8 changes: 3 additions & 5 deletions demo/src/com/mobeta/android/demodslv/DSLVFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,10 @@ protected int getLayout() {
* Return list item layout resource passed to the ArrayAdapter.
*/
protected int getItemLayout() {
boolean handleRight = false;
if (removeMode == DragSortController.FLING_LEFT_REMOVE || removeMode == DragSortController.SLIDE_LEFT_REMOVE) {
handleRight = true;
}

if (handleRight) {
return R.layout.list_item_handle_right;
} else if (removeMode == DragSortController.CLICK_REMOVE) {
return R.layout.list_item_click_remove;
} else {
return R.layout.list_item_handle_left;
}
Expand Down Expand Up @@ -111,6 +108,7 @@ public DragSortController buildController(DragSortListView dslv) {
// removeMode = flingRight
DragSortController controller = new DragSortController(dslv);
controller.setDragHandleId(R.id.drag_handle);
controller.setClickRemoveId(R.id.click_remove);
controller.setRemoveEnabled(removeEnabled);
controller.setSortEnabled(sortEnabled);
controller.setDragInitMode(dragStartMode);
Expand Down
4 changes: 3 additions & 1 deletion demo/src/com/mobeta/android/demodslv/TestBedDSLV.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_bed_main);

getSupportFragmentManager().beginTransaction().add(R.id.test_bed, getNewDslvFragment(), mTag).commit();
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.test_bed, getNewDslvFragment(), mTag).commit();
}
}

@Override
Expand Down
23 changes: 6 additions & 17 deletions library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,24 @@ Copyright 2012 Andreas Schildbach
<groupId>com.mobeta.android.dslv</groupId>
<artifactId>drag-sort-listview</artifactId>
<packaging>apklib</packaging>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>

<parent>
<groupId>com.mobeta.android.dslv</groupId>
<artifactId>parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.1_r1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
<optional>true</optional>
</dependency>
</dependencies>
Expand All @@ -52,20 +50,11 @@ Copyright 2012 Andreas Schildbach
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.2</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
</plugin>
</plugins>
</pluginManagement>

</build>
</project>
12 changes: 8 additions & 4 deletions library/res/values/dslv_attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
<attr name="max_drag_scroll_speed" format="float" />
<attr name="float_background_color" format="color" />
<attr name="remove_mode">
<enum name="flingRight" value="0" />
<enum name="flingLeft" value="1" />
<enum name="slideRight" value="2" />
<enum name="slideLeft" value="3" />
<enum name="clickRemove" value="0" />
<enum name="flingRight" value="1" />
<enum name="flingLeft" value="2" />
<enum name="slideRight" value="3" />
<enum name="slideLeft" value="4" />
</attr>
<attr name="track_drag_sort" format="boolean"/>
<attr name="float_alpha" format="float"/>
<attr name="slide_shuffle_speed" format="float"/>
<attr name="remove_animation_duration" format="integer"/>
<attr name="drop_animation_duration" format="integer"/>
<attr name="drag_enabled" format="boolean" />
<attr name="sort_enabled" format="boolean" />
<attr name="remove_enabled" format="boolean" />
Expand All @@ -23,6 +26,7 @@
<enum name="onLongPress" value="2"/>
</attr>
<attr name="drag_handle_id" format="integer" />
<attr name="click_remove_id" format="integer" />
<attr name="use_default_controller" format="boolean" />
</declare-styleable>
</resources>
Loading

0 comments on commit a645bab

Please sign in to comment.