{"id":13690267,"url":"https://github.com/bauerca/drag-sort-listview","last_synced_at":"2025-05-15T01:04:44.407Z","repository":{"id":3462493,"uuid":"4516733","full_name":"bauerca/drag-sort-listview","owner":"bauerca","description":"Android ListView with drag and drop reordering.","archived":false,"fork":false,"pushed_at":"2019-08-02T05:11:18.000Z","size":2461,"stargazers_count":3200,"open_issues_count":65,"forks_count":1432,"subscribers_count":303,"default_branch":"master","last_synced_at":"2025-04-06T17:09:50.644Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bauerca.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-01T06:32:13.000Z","updated_at":"2025-03-23T03:51:42.000Z","dependencies_parsed_at":"2022-08-03T12:20:42.912Z","dependency_job_id":null,"html_url":"https://github.com/bauerca/drag-sort-listview","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bauerca%2Fdrag-sort-listview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bauerca%2Fdrag-sort-listview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bauerca%2Fdrag-sort-listview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bauerca%2Fdrag-sort-listview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bauerca","download_url":"https://codeload.github.com/bauerca/drag-sort-listview/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248785055,"owners_count":21161225,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T16:00:53.715Z","updated_at":"2025-04-13T21:29:20.239Z","avatar_url":"https://github.com/bauerca.png","language":"Java","readme":"DragSortListView\n================\n\n# NOTICE: No longer maintained.\n\nI do not have much time to devote to this project so I am\ndropping support for the time being. Sorry everybody!\n\nNews\n----\n\n**April 2, 2013**: Hey all. If you want to send a pull request,\nplease read the [Contributing](https://github.com/bauerca/drag-sort-listview#contributing) section first. Thanks!\n\n**Feb. 9, 2013**: Version 0.6.0. Consolidated remove modes to\n`click_remove` and `fling_remove`. No more fling remove while\ndragging; fling anywhere on item to remove it.\n[Leszek Mzyk](https://github.com/imbryk) is a bona fide code-slanger.\n\n**Jan. 10, 2013**: Version 0.5.0 is released. Supports ListView\nmulti-choice and single-choice modes thanks to the hard work of\n[Mattias Flodin](https://github.com/mattiasflodin)! Awesome-sauce.\nCheck out the new demos.\n\n**Nov. 23, 2012**: Hmmm, what's this? \u0026rarr; [Gittip](https://www.gittip.com/bauerca) :)\n\n**Nov. 17, 2012**: [Drag-Sort Demos](https://play.google.com/store/apps/details?id=com.mobeta.android.demodslv)\napp in Google Play Store!\n\n**Nov. 15, 2012**: Smooth operation! Drops and removals are animated.\nAlso, DragSortController now provides a convenience\nclick-to-remove feature (see [XML attrs](https://github.com/bauerca/drag-sort-listview#xml-layout-declaration)\nand [RemoveListener](https://github.com/bauerca/drag-sort-listview#dragsortlistviewremovelistener)\nsections).\n\n**Nov. 11, 2012**: Mavenized.\nThanks to [Andreas Schildbach (Goonie)](https://github.com/Goonie)!\n\n**Oct. 30, 2012**: DragSortCursorAdapter class helps you reorder\na Cursor-backed ListAdapter. Look at ResourceDragSortCursorAdapter\nand SimpleDragSortCursorAdapter as well in [the API](\nhttp://bauerca.github.com/drag-sort-listview).\n\n**Oct. 19, 2012**: Public API documentation is up at\nhttp://bauerca.github.com/drag-sort-listview.\n\n**Oct. 19, 2012**: Refactoring rampage. Backward compatibility is slightly\nbroken. New features make it worthwhile :) and include: total floating\nView customization, total control over drag start/stop,\nand a helper class implementing common patterns (long-press to drag,\nfling-to-remove, etc.). Thanks to\n[Dan Hulme (orac)](https://github.com/orac)\nfor getting all this rolling!\nCheck out the extensively updated demos and usage section below.\n\n**Sept. 26, 2012**: Drag-sorting is now animated! (optional, of course)\nItems slide around underneath the floating (dragged) View.\n\nOverview\n--------\n\nDragSortListView (DSLV) is an extension of the Android ListView that enables\ndrag-and-drop reordering of list items. It is a ~~major overhaul~~ complete\nrewrite of\nthe [TouchInterceptor](https://github.com/android/platform_packages_apps_music/blob/master/src/com/android/music/TouchInterceptor.java) (TI) \nmeant to give drag-sorting a polished feel. Some key features are:\n\n1. Clean drag and drop (no visual glitches; I hope!)\n2. Intuitive and smooth scrolling while dragging.\n3. Support for heterogeneous item heights.\n4. Public `startDrag()` and `stopDrag()` methods.\n5. Public interface for customizing the floating View.\n\nDragSortListView is useful for all kinds of prioritized lists:\nfavorites, playlists, checklists, etc. Would love to hear about\nyour use case or app by email.\nI hope you find it useful; and please, help me improve the thing!\n\nWidget usage\n------------\n\nThree major elements define the drag-sort process. Roughly, in\norder of importance, they are:\n\n1. **Data reordering**. Drag-sorts reorder the data\nunderlying your list. Since DSLV\ncannot know how you organize your data, the reordering must be\nperformed by you using the provided Listener interfaces.\n2. **Drag start/stop**. Drags are started and stopped by\ncalling `startDrag()` and\n`stopDrag()` on your DSLV instance; but some help that is.\nThe convenience class, DragSortController, provides all kinds of\nboiler-plate for common start/stop/remove drag patterns.\n3. **Floating View**. The floating View appearance and behavior is\ncontrolled by an\nimplementation of the FloatViewManager interface. With this, you\ncan display any View you like as the floating View, and update its\nappearance/location on every touch event. The DragSortController\nhelper class also implements this interface for convenience.\n\nNumber 1 is essential. As mentioned above, 2 and 3 can\nbe handled by the DragSortController helper class. Keep reading,\nthen head to the\ndemo and start studying some examples.\n\n\n### XML layout declaration\n\nDragSortListView can be declared in an XML layout file just like\nthe ListView. Several example layout files are\n[provided in the demo](https://github.com/bauerca/drag-sort-listview/blob/master/demo/res/layout/).\nThe available attributes (in addition to the usual\nListView attributes) are given below. Read each bullet as\n\n* `\u003cxml attr\u003e`: (`\u003cdatatype\u003e`, `\u003cdefault value\u003e`) `\u003cdescription\u003e`.\n\n#### XML attributes\n\n* `collapsed_height`: (dimension, 1px) Height of placeholder at original\ndrag position. Cannot be zero.\n* `drag_scroll_start`: (float, 0.3) Start of drag-scroll regions\n(defined by a\nfraction of the total DSLV height; i.e. between 0 and 1).\n* `max_drag_scroll_speed`: (float, 0.5) Maximum drag-scroll speed for\ndefault linear drag-scroll profile. Units of pixels/millisecond.\n* `float_alpha`: (float, 1.0) Transparency of floating View. Value from\n0 to 1 where 1 is opaque.\n* `slide_shuffle_speed`: (float, 0.7) Speed of shuffle animations\nunderneath floating View. A value\nof 0 means a shuffle animation is always in progress, whereas a value\nof 1 means items snap from position to position without animation.\n* `drop_animation_duration`: (int, 150) Drop animation smoothly centers\n  the floating View over the drop slot before destroying it. Duration\n  in milliseconds.\n* `remove_animation_duration`: (int, 150) Remove animation smoothly\n  collapses the empty slot when an item is removed. Duration\n  in milliseconds.\n* `track_drag_sort`: (bool, false) Debugging option; explained below.\n* `use_default_controller`: (bool, true) Have DSLV create a\n  DragSortController instance and pass the following xml attributes\n  to it. If you set this to false, ignore the following attributes.\n* `float_background_color`: (color, BLACK) Set the background\n  color of the floating View when using the default\n  DragSortController. Floating View in this case is a snapshot of\n  the list item to be dragged.\n* `drag_handle_id`: (id, 0) Android resource id that points to a\n  child View of a list item (or the root View of the list item\n  layout). This identifies the \"drag handle,\" or the View within a\n  list item that must\n  be touched to start a drag-sort of that item.\n  Required if drags are to be enabled using the default\n  DragSortController.\n* `sort_enabled`: (bool, true) Enable sorting of dragged item (disabling\n  is useful when you only want item removal).\n* `drag_start_mode`: (enum, \"onDown\") Sets the gesture for starting\n  a drag.\n    + \"onDown\": Drag starts when finger touches down\n      on the drag handle.\n    + \"onDrag\": Drag starts when finger touches down on drag handle\n      and then drags (allows item clicks and long clicks).\n    + \"onLongPress\": Drag starts on drag handle long press (allows\n      item clicks).\n* `remove_enabled`: (bool, false) Enable dragged item removal by one\n  of the `remove_mode` options below.\n* `remove_mode`: (enum, \"flingRight\") Sets the gesture for removing the\n  dragged item.\n    + \"clickRemove\": Click on item child View with id `click_remove_id`.\n    + \"flingRemove\": Fling horizontal anywhere on item.\n* `click_remove_id`: (id, 0) Android resource id that points to a\n  child View of a list item. When `remove_mode=\"clickRemove\"` and\n  `remove_enabled=\"true\"`, a click on this child View removes the\n  containing item. This attr is used by DragSortController.\n* `fling_handle_id`: (id, 0) Android resource id that points to a\n  child View of a list item. When `remove_mode=\"flingRemove\"` and\n  `remove_enabled=\"true\"`, a fling that originates on this child\n  View removes the containing item. This attr is used by\n  DragSortController.\n\n### Listeners\n\nDragSortListView is a ListView, and thus requires a [ListAdapter](http://developer.android.com/reference/android/widget/ListAdapter.html)\nto populate\nits items. Drag-sorting additionally implies a reordering of the items\nin the ListAdapter, achieved through callbacks to special Listener\ninterfaces\ndefined in DSLV. Listeners can be registered with DSLV in two ways:\n\n1. Pass them individually to the `set*Listener()` methods\n2. Implement the Listener interfaces you require in a custom\nListAdapter; when `DragSortListView.setAdapter()` is called\nwith your custom\nAdapter, DSLV detects which interfaces are implemented and calls\nthe appropriate `set*Listener()` methods on itself with the\nprovided ListAdapter as argument.\n\nEach Listener interface is described below:\n\n#### DragSortListView.DropListener\n\nThe DropListener interface has a single callback:\n```java\npublic void drop(int from, int to);\n```\nThis is called upon completion of the drag-sort; i.e. when the\nfloating View is dropped.\nThe parameter `from` is the ListView item that was originally dragged,\nand `to` is the position where the item was dropped.\nThis is an important callback; without\na DropListener, DSLV is for all practical purposes useless.\n\nFor proper DSLV operation, this callback must perform\na reordering of the data in your ListAdapter. For example, one often\nhas a Cursor that pulls from a database and backs a\nCursorAdapter. The order of items in the\nCursor is fixed; therefore, given drag-sorting, you must implement\na mapping from Cursor positions to DSLV positions. This is commonly\ndone\nwithin in a custom ListAdapter or CursorWrapper that implements the\nDropListener interface. See Issue #20 for a discussion of this.\n**Update**: Or simply use the DragSortCursorAdapter class!\n\nIf your DSLV instance `android:choiceMode` is not `\"none\"`, and your\nListAdapter does not have stable ids, you must call\n[DragSortListView.moveCheckState(int from, int to)](http://bauerca.github.com/drag-sort-listview/reference/com/mobeta/android/dslv/DragSortListView.html#moveCheckState(int, int\\))\nwithin `drop(from, to)`. See the documentation in the DSLV API for more\ninfo.\n\n#### DragSortListView.RemoveListener\n\nAs the TI did, DSLV provides gestures for removing the floating\nView (and its associated list item) from the list. Upon completion of\na remove gesture, DSLV calls the RemoveListener method:\n```java\npublic void remove(int which);\n```\nThe position `which` should be \"removed\" from your ListAdapter; i.e.\nthe mapping from your data (e.g. in a Cursor) to your ListAdapter\nshould henceforth neglect the item previously pointed to by `which`.\nWhether you actually remove the data or not is up to you.\n\nItem removal can now happen outside of a drag event. The method\n`DragSortListView.removeItem(int position)` can be called at any time.\n\nIf your DSLV instance `android:choiceMode` is not `\"none\"`, and your\nListAdapter does not have stable ids, you must call\n[DragSortListView.removeCheckState(int position)](http://bauerca.github.com/drag-sort-listview/reference/com/mobeta/android/dslv/DragSortListView.html#removeCheckState(int\\))\nwithin `remove(which)`. See the documentation in the DSLV API for more\ninfo.\n\n#### DragSortListView.DragListener\n\nThe callback in the DragListener is\n```java\npublic void drag(int from, int to);\n```\nThis is called whenever the floating View hovers to a new potential\ndrop position; `to` is the current potential drop position, and `from` is\nthe previous one. The TI provided this callback; an example of usage\ndoes not come to mind.\n\n#### DragSortListView.DragSortListener\n\nThis is a convenience interface which combines all of the above\nListener interfaces.\n\n### FloatViewManager\n\nThis is the interface that handles creation, updates, and tear-downs\nof the floating View. It is passed to DSLV using the\n`setFloatViewManager()` method. Example usage can be found in\nthe SimpleFloatViewManager, which\nis a convenience class\nthat simply takes a snapshot of the list item to be dragged.\n\nIf you want to spice up the floating View, implement your own\nFloatViewManager. In your\n`onCreateFloatView()` method, you should make sure that the View\nyou return has a definite height (do not use MATCH_PARENT! although\nMATCH_PARENT is perfectly okay for the layout width).\nDSLV will measure and layout your floating View according to\nthe ViewGroup.LayoutParams attached to it. If no LayoutParams are\nattached, DSLV will use WRAP_CONTENT and MATCH_PARENT as the layout\nheight and width.\n\n### Drag start/stop\n\nAs of DragSortListView 0.3.0, drag start and stop behavior is all up\nto you. Feel free to call `startDrag()` or `stopDrag()` on the\nDSLV instance whenever you please. Be aware that if no\ntouch event is in progress when `startDrag()` is called, the drag will\nnot start. But don't waste too much time working on your own drag\ninitiation if it's simple; the DragSortController described below\nwill do that for you.\n\n### DragSortController\n\nThe DragSortController\nis a convenience class that implements some common\ndesign patterns for initiating drags or removing the dragged item\nfrom the list. It implements\nthe View.OnTouchListener interface to watch touch events as they are\ndispatched to DSLV. It also implements the FloatViewManager interface\n(by subclassing SimpleFloatViewManager) to handle simple floating View\ncreation. If you do not use XML to create\nthe default DragSortController, you must pass in your own\ninstance of DragSortController\nto both the `setFloatViewManager()` *and* `setOnTouchListener()`\nmethods of the DSLV instance.\n\nThe default behavior of the DragSortController expects list items\nthat are drag enabled to have a child View called a \"drag handle.\"\nThe drag handle View should have an associated android resource id,\nand that id should\nbe passed into the DragSortController (the id can be set in XML if\n`use_default_controller` is `true`). If a touch event lands on the\ndrag handle of an item, and a gesture is detected that should start a\ndrag, the drag starts.\n\n\nAdditional documentation\n------------------------\n\nThere is limited documentation in the DSLV.\nYou can check it\nout with Javadoc by navigating to `/path/to/drag-sort-listview/src/` and\ntyping\n\n    javadoc com.mobeta.android.dslv *\n\nThe javadoc can be viewed on the DSLV project page:\nhttp://bauerca.github.com/drag-sort-listview. Sorry for the many\nbroken links at the moment. I am slowly getting to this.\n\nInstallation\n------------\n\nDownload and install the [Android sdk](http://developer.android.com/sdk/index.html). Clone/Download/Fork the repo\nthrough GitHub or via (read-only)\n\n    git clone https://github.com/bauerca/drag-sort-listview.git\n\n### Ant\n\nExecute the following in both the drag-sort-listview/library/ and\ndrag-sort-listview/demo/ directories (assuming\n/path/to/android_sdk/tools is in your PATH):\n\n    android update project --path ./\n\nTo test out the demo, navigate to drag-sort-listview/demo/ and\nexecute\n\n    ant debug install\n\nto build and install the demo on your connected device/emulator.\n\n### Maven\n\nA simple\n\n    mvn clean install\n\nshould suffice to build and put the DSLV lib and demo in your local\nmaven repository. To include in your project, add the following\ndependency to your pom.xml:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.mobeta.android.dslv\u003c/groupId\u003e\n    \u003cartifactId\u003edrag-sort-listview\u003c/artifactId\u003e\n    \u003cversion\u003e0.6.1-SNAPSHOT\u003c/version\u003e\n    \u003ctype\u003eapklib\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\n### Installation in Eclipse (Indigo)\n\nThe first step is to choose File \u003e Import or right-click in the Project Explorer\nand choose Import. If you don't use E-Git to integrate Eclipse with Git, skip\nthe rest of this paragraph. Choose \"Projects from Git\" as the import source.\nFrom the Git page, click Clone, and enter the URI of this repository. That's the\nonly text box to fill in on that page. On the following pages, choose which\nbranches to clone (probably all of them) and where to keep the local checkout,\nand then click Finish. Once the clone has finished, pick your new repository\nfrom the list, and on the following page select 'Use the New Projects wizard'.\n\nFrom here the process is the same even if you don't use E-Git. Choose 'Android\nProject from Existing Code' and then browse to where you checked out DSLV. You\nshould then see two projects in the list: one named after the directory name,\nand the other called com.mobeta.android.demodslv.Launcher . The top one is the\nlibrary project, and the bottom one the demo project. You probably want both at\nfirst, so just click Finish.\n\nFinally, to add the library to your application project, right-click your\nproject in the Package Explorer and select Properties. Pick the \"Android\" page,\nand click \"Add...\" from the bottom half. You should see a list including the\nDSLV project as well as any others in your workspace.\n\nContributing\n------------\n\nFirst of all, thank you! Many of your pull requests have added\ntremendous value to this project. Your efforts are truly appreciated!\n\nNow that the project is fairly mature, I would like to lay out\nsome (loose) rules for future pull requests. So far I have\nonly one (of course, you should help me add more). Here's the list:\n\n* Avoid pull requests that are small tweaks to default\n  DragSortController behavior. This class is merely a guide/helper\n  for creating more complex drag-sort interactions. For example,\n  if you don't\n  like the feel of the default fling-remove initiation for your\n  app, then you should not create a pull request that \"fixes\"\n  the behavior. Rather, try to modify or subclass DragSortController\n  for your particular needs. That said, if a \"must-have\" touch\n  pattern arises, I think there is some wiggle room in this rule.\n\n\nDebugging\n---------\n\nIf you have python and [matplotlib](http://matplotlib.sourceforge.net/)\ninstalled, you can use the script dslv.py\nto debug drag-sort behavior. This script\nis found in the project tools/ directory.\n\nTo enable, just set the `dslv:track_drag_sort` attribute to\n`\"true\"` in XML. While drag-sorting on your emulator or device,\nthis tracking causes the DSLV to periodically dump its state to\na file called dslv_state.txt in the device/emulator /sdcard/ directory. \n\nNavigate to the location of dslv.py, and do \n\n    adb [-e|-d|-s device] pull /sdcard/dslv_state.txt\n\nthen simply run\n\n    python dslv.py\n\nAn image should appear that represents the DSLV in the final\nrecorded state. Right and left keys allow stepping\nthrough the recorded drag-sort frame-by-frame; up/down keys jump\n30 frames. This tool has\nbeen very useful for debugging jumpy behavior while drag-scrolling.\n\nLicense\n-------\n\n```\nA subclass of the Android ListView component that enables drag\nand drop re-ordering of list items.\n\nCopyright 2012 Carl Bauer\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\n","funding_links":[],"categories":["Libraries","etc","库"],"sub_categories":["GUI","[](https://github.com/JStumpp/awesome-android/blob/master/readme.md#gui)GUI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbauerca%2Fdrag-sort-listview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbauerca%2Fdrag-sort-listview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbauerca%2Fdrag-sort-listview/lists"}