diff --git a/app/build.gradle b/app/build.gradle index 32815916..a83025fa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,6 +59,6 @@ dependencies { compile('com.crashlytics.sdk.android:crashlytics:2.1.0@aar') { transitive = true; } - compile files('/Users/karim/Google Drive/Dokumente/AndroidStudioProjects/MaterialMusic/libs/jaudiotagger-2.0.4-20111207.115108-15.jar') - compile project(':libraries:drag-sort-listview:library') + compile files('../libs/jaudiotagger-2.0.4-20111207.115108-15.jar') + compile 'asia.ivity.android:drag-sort-listview:1.0' } diff --git a/libraries/drag-sort-listview/.gitignore b/libraries/drag-sort-listview/.gitignore deleted file mode 100644 index 59a4bfab..00000000 --- a/libraries/drag-sort-listview/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# built application files -*.apk -*.ap_ - -# files for the dex VM -*.dex - -# Java class files -*.class - -# generated files -bin/ -gen/ -target/ - -# external libraries -libs/ - -# gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties -.gitattributes - -# Eclipse project files -.classpath -.project - -# Android Studio -*.iml -.idea - -# Mac -.DS_Store diff --git a/libraries/drag-sort-listview/CHANGELOG.md b/libraries/drag-sort-listview/CHANGELOG.md deleted file mode 100644 index 81335198..00000000 --- a/libraries/drag-sort-listview/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -Changelog -========= - -0.6.2 ------ -* Add gradle build files -* Minor fixes & cleanups (see git log) - -0.6.1 ------ - -* Add git version tags -* Fix #77: OnClickListener in list item crashes -DragSortController. -* Fix #81: Enabling FastScroller causes crash. - -0.6.0 ------ - -* Remove modes are now `fling_remove` and `click_remove`. - -0.5.0 ------ - -* Multiple-choice and single-choice selections handled. - -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)`. diff --git a/libraries/drag-sort-listview/README.md b/libraries/drag-sort-listview/README.md deleted file mode 100644 index 6e9bc3fa..00000000 --- a/libraries/drag-sort-listview/README.md +++ /dev/null @@ -1,439 +0,0 @@ -DragSortListView -================ - -The original project is no longer maintained. I intend to maintain this fork of the project to a limited extent. -The following things I intend to maintain: -* API levels -* Compatibility with Android Studio -* Bugs if found - -I don't intend to add any new features although I may adjust things here and there in the codebase. - -Overview --------- - -DragSortListView (DSLV) is an extension of the Android ListView that enables -drag-and-drop reordering of list items. It is a ~~major overhaul~~ complete -rewrite of -the [TouchInterceptor](https://github.com/android/platform_packages_apps_music/blob/master/src/com/android/music/TouchInterceptor.java) (TI) -meant to give drag-sorting a polished feel. Some key features are: - -1. Clean drag and drop (no visual glitches; I hope!) -2. Intuitive and smooth scrolling while dragging. -3. Support for heterogeneous item heights. -4. Public `startDrag()` and `stopDrag()` methods. -5. Public interface for customizing the floating View. - -DragSortListView is useful for all kinds of prioritized lists: -favorites, playlists, checklists, etc. Would love to hear about -your use case or app by email. -I hope you find it useful; and please, help me improve the thing! - -Widget usage ------------- - -Three major elements define the drag-sort process. Roughly, in -order of importance, they are: - -1. **Data reordering**. Drag-sorts reorder the data -underlying your list. Since DSLV -cannot know how you organize your data, the reordering must be -performed by you using the provided Listener interfaces. -2. **Drag start/stop**. Drags are started and stopped by -calling `startDrag()` and -`stopDrag()` on your DSLV instance; but some help that is. -The convenience class, DragSortController, provides all kinds of -boiler-plate for common start/stop/remove drag patterns. -3. **Floating View**. The floating View appearance and behavior is -controlled by an -implementation of the FloatViewManager interface. With this, you -can display any View you like as the floating View, and update its -appearance/location on every touch event. The DragSortController -helper class also implements this interface for convenience. - -Number 1 is essential. As mentioned above, 2 and 3 can -be handled by the DragSortController helper class. Keep reading, -then head to the -demo and start studying some examples. - - -### XML layout declaration - -DragSortListView can be declared in an XML layout file just like -the ListView. Several example layout files are -[provided in the demo](https://github.com/bauerca/drag-sort-listview/blob/master/demo/res/layout/). -The available attributes (in addition to the usual -ListView attributes) are given below. Read each bullet as - -* ``: (``, ``) ``. - -#### XML attributes - -* `collapsed_height`: (dimension, 1px) Height of placeholder at original -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). -* `max_drag_scroll_speed`: (float, 0.5) Maximum drag-scroll speed for -default linear drag-scroll profile. Units of pixels/millisecond. -* `float_alpha`: (float, 1.0) Transparency of floating View. Value from -0 to 1 where 1 is opaque. -* `slide_shuffle_speed`: (float, 0.7) Speed of shuffle animations -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 - to it. If you set this to false, ignore the following attributes. -* `float_background_color`: (color, BLACK) Set the background - color of the floating View when using the default - DragSortController. Floating View in this case is a snapshot of - the list item to be dragged. -* `drag_handle_id`: (id, 0) Android resource id that points to a - child View of a list item (or the root View of the list item - layout). This identifies the "drag handle," or the View within a - list item that must - be touched to start a drag-sort of that item. - Required if drags are to be enabled using the default - DragSortController. -* `sort_enabled`: (bool, true) Enable sorting of dragged item (disabling - is useful when you only want item removal). -* `drag_start_mode`: (enum, "onDown") Sets the gesture for starting - a drag. - + "onDown": Drag starts when finger touches down - on the drag handle. - + "onDrag": Drag starts when finger touches down on drag handle - and then drags (allows item clicks and long clicks). - + "onLongPress": Drag starts on drag handle long press (allows - item clicks). -* `remove_enabled`: (bool, false) Enable dragged item removal by one - 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`. - + "flingRemove": Fling horizontal anywhere on 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. -* `fling_handle_id`: (id, 0) Android resource id that points to a - child View of a list item. When `remove_mode="flingRemove"` and - `remove_enabled="true"`, a fling that originates on this child - View removes the containing item. This attr is used by - DragSortController. - -### Listeners - -DragSortListView is a ListView, and thus requires a [ListAdapter](http://developer.android.com/reference/android/widget/ListAdapter.html) -to populate -its items. Drag-sorting additionally implies a reordering of the items -in the ListAdapter, achieved through callbacks to special Listener -interfaces -defined in DSLV. Listeners can be registered with DSLV in two ways: - -1. Pass them individually to the `set*Listener()` methods -2. Implement the Listener interfaces you require in a custom -ListAdapter; when `DragSortListView.setAdapter()` is called -with your custom -Adapter, DSLV detects which interfaces are implemented and calls -the appropriate `set*Listener()` methods on itself with the -provided ListAdapter as argument. - -Each Listener interface is described below: - -#### DragSortListView.DropListener - -The DropListener interface has a single callback: -```java -public void drop(int from, int to); -``` -This is called upon completion of the drag-sort; i.e. when the -floating View is dropped. -The parameter `from` is the ListView item that was originally dragged, -and `to` is the position where the item was dropped. -This is an important callback; without -a DropListener, DSLV is for all practical purposes useless. - -For proper DSLV operation, this callback must perform -a reordering of the data in your ListAdapter. For example, one often -has a Cursor that pulls from a database and backs a -CursorAdapter. The order of items in the -Cursor is fixed; therefore, given drag-sorting, you must implement -a mapping from Cursor positions to DSLV positions. This is commonly -done -within in a custom ListAdapter or CursorWrapper that implements the -DropListener interface. See Issue #20 for a discussion of this. -**Update**: Or simply use the DragSortCursorAdapter class! - -If your DSLV instance `android:choiceMode` is not `"none"`, and your -ListAdapter does not have stable ids, you must call -[DragSortListView.moveCheckState(int from, int to)](http://bauerca.github.com/drag-sort-listview/reference/com/mobeta/android/dslv/DragSortListView.html#moveCheckState(int, int\)) -within `drop(from, to)`. See the documentation in the DSLV API for more -info. - -#### DragSortListView.RemoveListener - -As the TI did, DSLV provides gestures for removing the floating -View (and its associated list item) from the list. Upon completion of -a remove gesture, DSLV calls the RemoveListener method: -```java -public void remove(int which); -``` -The position `which` should be "removed" from your ListAdapter; i.e. -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. - -If your DSLV instance `android:choiceMode` is not `"none"`, and your -ListAdapter does not have stable ids, you must call -[DragSortListView.removeCheckState(int position)](http://bauerca.github.com/drag-sort-listview/reference/com/mobeta/android/dslv/DragSortListView.html#removeCheckState(int\)) -within `remove(which)`. See the documentation in the DSLV API for more -info. - -#### DragSortListView.DragListener - -The callback in the DragListener is -```java -public void drag(int from, int to); -``` -This is called whenever the floating View hovers to a new potential -drop position; `to` is the current potential drop position, and `from` is -the previous one. The TI provided this callback; an example of usage -does not come to mind. - -#### DragSortListView.DragSortListener - -This is a convenience interface which combines all of the above -Listener interfaces. - -### FloatViewManager - -This is the interface that handles creation, updates, and tear-downs -of the floating View. It is passed to DSLV using the -`setFloatViewManager()` method. Example usage can be found in -the SimpleFloatViewManager, which -is a convenience class -that simply takes a snapshot of the list item to be dragged. - -If you want to spice up the floating View, implement your own -FloatViewManager. In your -`onCreateFloatView()` method, you should make sure that the View -you return has a definite height (do not use MATCH_PARENT! although -MATCH_PARENT is perfectly okay for the layout width). -DSLV will measure and layout your floating View according to -the ViewGroup.LayoutParams attached to it. If no LayoutParams are -attached, DSLV will use WRAP_CONTENT and MATCH_PARENT as the layout -height and width. - -### Drag start/stop - -As of DragSortListView 0.3.0, drag start and stop behavior is all up -to you. Feel free to call `startDrag()` or `stopDrag()` on the -DSLV instance whenever you please. Be aware that if no -touch event is in progress when `startDrag()` is called, the drag will -not start. But don't waste too much time working on your own drag -initiation if it's simple; the DragSortController described below -will do that for you. - -### DragSortController - -The DragSortController -is a convenience class that implements some common -design patterns for initiating drags or removing the dragged item -from the list. It implements -the View.OnTouchListener interface to watch touch events as they are -dispatched to DSLV. It also implements the FloatViewManager interface -(by subclassing SimpleFloatViewManager) to handle simple floating View -creation. If you do not use XML to create -the default DragSortController, you must pass in your own -instance of DragSortController -to both the `setFloatViewManager()` *and* `setOnTouchListener()` -methods of the DSLV instance. - -The default behavior of the DragSortController expects list items -that are drag enabled to have a child View called a "drag handle." -The drag handle View should have an associated android resource id, -and that id should -be passed into the DragSortController (the id can be set in XML if -`use_default_controller` is `true`). If a touch event lands on the -drag handle of an item, and a gesture is detected that should start a -drag, the drag starts. - - -Additional documentation ------------------------- - -There is limited documentation in the DSLV. -You can check it -out with Javadoc by navigating to `/path/to/drag-sort-listview/src/` and -typing - - javadoc com.mobeta.android.dslv * - -The javadoc can be viewed on the DSLV project page: -http://bauerca.github.com/drag-sort-listview. Sorry for the many -broken links at the moment. I am slowly getting to this. - -Installation ------------- - -Download and install the [Android sdk](http://developer.android.com/sdk/index.html). Clone/Download/Fork the repo -through GitHub or via (read-only) - - git clone https://github.com/bauerca/drag-sort-listview.git - -### Ant - -Execute the following in both the drag-sort-listview/library/ and -drag-sort-listview/demo/ directories (assuming -/path/to/android_sdk/tools is in your PATH): - - android update project --path ./ - -To test out the demo, navigate to drag-sort-listview/demo/ and -execute - - ant debug install - -to build and install the demo on your connected device/emulator. - -### Maven - -A simple - - mvn clean install - -should suffice to build and put the DSLV lib and demo in your local -maven repository. To include in your project, add the following -dependency to your pom.xml: - -```xml - - com.mobeta.android.dslv - drag-sort-listview - 0.6.1-SNAPSHOT - apklib - -``` - -### Installation in Eclipse (Indigo) - -The first step is to choose File > Import or right-click in the Project Explorer -and choose Import. If you don't use E-Git to integrate Eclipse with Git, skip -the rest of this paragraph. Choose "Projects from Git" as the import source. -From the Git page, click Clone, and enter the URI of this repository. That's the -only text box to fill in on that page. On the following pages, choose which -branches to clone (probably all of them) and where to keep the local checkout, -and then click Finish. Once the clone has finished, pick your new repository -from the list, and on the following page select 'Use the New Projects wizard'. - -From here the process is the same even if you don't use E-Git. Choose 'Android -Project from Existing Code' and then browse to where you checked out DSLV. You -should then see two projects in the list: one named after the directory name, -and the other called com.mobeta.android.demodslv.Launcher . The top one is the -library project, and the bottom one the demo project. You probably want both at -first, so just click Finish. - -Finally, to add the library to your application project, right-click your -project in the Package Explorer and select Properties. Pick the "Android" page, -and click "Add..." from the bottom half. You should see a list including the -DSLV project as well as any others in your workspace. - -### Installation in Android Studio (as of version 0.4.0) - -Ideally there would be a copy of this project available in the Maven Central -repository but since this is a very unofficial fork of the project I am not -going to go through the process of adding it there. The way I would recommend -adding this library to your app is by using a git submodule. In the root -directory of your project you can do something like this: -```sh -mkdir libraries -cd libraries -git submodule add https://github.com/JayH5/drag-sort-listview.git -echo "include ':libraries:drag-sort-listview:library'" >> ../settings.gradle -``` -Then add the following dependency to your build.gradle project: -```groovy -compile project(':libraries:drag-sort-listview:library') -``` - -Contributing ------------- - -First of all, thank you! Many of your pull requests have added -tremendous value to this project. Your efforts are truly appreciated! - -Now that the project is fairly mature, I would like to lay out -some (loose) rules for future pull requests. So far I have -only one (of course, you should help me add more). Here's the list: - -* Avoid pull requests that are small tweaks to default - DragSortController behavior. This class is merely a guide/helper - for creating more complex drag-sort interactions. For example, - if you don't - like the feel of the default fling-remove initiation for your - app, then you should not create a pull request that "fixes" - the behavior. Rather, try to modify or subclass DragSortController - for your particular needs. That said, if a "must-have" touch - pattern arises, I think there is some wiggle room in this rule. - - -Debugging ---------- - -If you have python and [matplotlib](http://matplotlib.sourceforge.net/) -installed, you can use the script dslv.py -to debug drag-sort behavior. This script -is found in the project tools/ directory. - -To enable, just set the `dslv:track_drag_sort` attribute to -`"true"` in XML. While drag-sorting on your emulator or device, -this tracking causes the DSLV to periodically dump its state to -a file called dslv_state.txt in the device/emulator /sdcard/ directory. - -Navigate to the location of dslv.py, and do - - adb [-e|-d|-s device] pull /sdcard/dslv_state.txt - -then simply run - - python dslv.py - -An image should appear that represents the DSLV in the final -recorded state. Right and left keys allow stepping -through the recorded drag-sort frame-by-frame; up/down keys jump -30 frames. This tool has -been very useful for debugging jumpy behavior while drag-scrolling. - -License -------- - -``` -A subclass of the Android ListView component that enables drag -and drop re-ordering of list items. - -Copyright 2012 Carl Bauer - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -``` - diff --git a/libraries/drag-sort-listview/build.gradle b/libraries/drag-sort-listview/build.gradle deleted file mode 100644 index 90153f8f..00000000 --- a/libraries/drag-sort-listview/build.gradle +++ /dev/null @@ -1,9 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' - } -} diff --git a/libraries/drag-sort-listview/demo/.gitignore b/libraries/drag-sort-listview/demo/.gitignore deleted file mode 100644 index fb8e9e09..00000000 --- a/libraries/drag-sort-listview/demo/.gitignore +++ /dev/null @@ -1,20 +0,0 @@ -# built application files -*.apk -*.ap_ - -# files for the dex VM -*.dex - -# Java class files -*.class - -# generated files -bin/ -gen/ - -# Local configuration file (sdk path, etc) -local.properties - -# Eclipse project files -.classpath -.project diff --git a/libraries/drag-sort-listview/demo/AndroidManifest.xml b/libraries/drag-sort-listview/demo/AndroidManifest.xml deleted file mode 100644 index 9aaa5b69..00000000 --- a/libraries/drag-sort-listview/demo/AndroidManifest.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libraries/drag-sort-listview/demo/app-description.txt b/libraries/drag-sort-listview/demo/app-description.txt deleted file mode 100644 index 8e2ba2ed..00000000 --- a/libraries/drag-sort-listview/demo/app-description.txt +++ /dev/null @@ -1,28 +0,0 @@ -This is a demo app for the DragSortListView library. The project is -hosted on GitHub with repo name: drag-sort-listview. - -DragSortListView is an extension of Android's ListView widget that -mediates drag-and-drop reordering of list items. Its primary purpose -is to provide an empty "drop slot" that tracks the dragged item, -effectively reordering the list on-the-fly. DragSortListView also -handles the tricky task of scrolling while dragging items over a long -list. Animated transitions give the process a seamless and intuitive -feel. - -Several convenience features accompany the basic functionality -described above. The most common drag initiation and item removal -techniques have been implemented for you and are accessed through -simple XML attributes:
- • Drag initiation: on touch, on drag, on long-press
- • Item removal: on click, on fling, on slide
- -The first demo, "Basic usage playground," exposes the basic -features of the library through the menu. You can dynamically -change drag initiation and item removal methods and add -headers/footers to the list. The rest of the demos address more -advanced usage. - -As you know, issues with the library that are voiced in the -comments will go unnoticed and left to wither. Please open an -issue ticket on the GitHub project page, or email me directly. -Thanks and happy dragging! diff --git a/libraries/drag-sort-listview/demo/build.gradle b/libraries/drag-sort-listview/demo/build.gradle deleted file mode 100644 index 06f3f910..00000000 --- a/libraries/drag-sort-listview/demo/build.gradle +++ /dev/null @@ -1,34 +0,0 @@ -apply plugin: 'com.android.application' - -dependencies { - compile project(':library') -} - -android { - compileSdkVersion 21 - buildToolsVersion "21.1.1" - - sourceSets { - main { - manifest.srcFile 'AndroidManifest.xml' - java.srcDirs = ['src'] - resources.srcDirs = ['src'] - aidl.srcDirs = ['src'] - renderscript.srcDirs = ['src'] - res.srcDirs = ['res'] - assets.srcDirs = ['assets'] - } - - // Move the tests to tests/java, tests/res, etc... - instrumentTest.setRoot('tests') - - // Move the build types to build-types/ - // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... - // This moves them out of them default location under src//... which would - // conflict with src/ being used by the main source set. - // Adding new build types or product flavors should be accompanied - // by a similar customization. - debug.setRoot('build-types/debug') - release.setRoot('build-types/release') - } -} diff --git a/libraries/drag-sort-listview/demo/pom.xml b/libraries/drag-sort-listview/demo/pom.xml deleted file mode 100644 index fd7ac4a7..00000000 --- a/libraries/drag-sort-listview/demo/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - 4.0.0 - - - com.mobeta.android.dslv - parent - 0.6.2-SNAPSHOT - ../pom.xml - - - com.mobeta.android.demodslv - drag-sort-listview-demo - apk - 0.6.2-SNAPSHOT - - - - com.mobeta.android.dslv - drag-sort-listview - ${project.version} - apklib - - - com.google.android - android - provided - - - com.google.android - support-v4 - - - - - src - test - - - - com.jayway.maven.plugins.android.generation2 - android-maven-plugin - - - - diff --git a/libraries/drag-sort-listview/demo/proguard-project.txt b/libraries/drag-sort-listview/demo/proguard-project.txt deleted file mode 100644 index f2fe1559..00000000 --- a/libraries/drag-sort-listview/demo/proguard-project.txt +++ /dev/null @@ -1,20 +0,0 @@ -# To enable ProGuard in your project, edit project.properties -# to define the proguard.config property as described in that file. -# -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in ${sdk.dir}/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/libraries/drag-sort-listview/demo/project.properties b/libraries/drag-sort-listview/demo/project.properties deleted file mode 100644 index a6cf15da..00000000 --- a/libraries/drag-sort-listview/demo/project.properties +++ /dev/null @@ -1,15 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system edit -# "ant.properties", and override values to adapt the script to your -# project structure. -# -# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): -#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt - -# Project target. -target=android-19 -android.library.reference.1=../library diff --git a/libraries/drag-sort-listview/demo/res/drawable-hdpi/delete_x.png b/libraries/drag-sort-listview/demo/res/drawable-hdpi/delete_x.png deleted file mode 100644 index 5b4244f7..00000000 Binary files a/libraries/drag-sort-listview/demo/res/drawable-hdpi/delete_x.png and /dev/null differ diff --git a/libraries/drag-sort-listview/demo/res/drawable-hdpi/drag.9.png b/libraries/drag-sort-listview/demo/res/drawable-hdpi/drag.9.png deleted file mode 100644 index 646c2eb5..00000000 Binary files a/libraries/drag-sort-listview/demo/res/drawable-hdpi/drag.9.png and /dev/null differ diff --git a/libraries/drag-sort-listview/demo/res/drawable-hdpi/dslv_launcher.png b/libraries/drag-sort-listview/demo/res/drawable-hdpi/dslv_launcher.png deleted file mode 100644 index bbfca16f..00000000 Binary files a/libraries/drag-sort-listview/demo/res/drawable-hdpi/dslv_launcher.png and /dev/null differ diff --git a/libraries/drag-sort-listview/demo/res/drawable-ldpi/dslv_launcher.png b/libraries/drag-sort-listview/demo/res/drawable-ldpi/dslv_launcher.png deleted file mode 100644 index 3e138276..00000000 Binary files a/libraries/drag-sort-listview/demo/res/drawable-ldpi/dslv_launcher.png and /dev/null differ diff --git a/libraries/drag-sort-listview/demo/res/drawable-mdpi/drag.9.png b/libraries/drag-sort-listview/demo/res/drawable-mdpi/drag.9.png deleted file mode 100644 index c90a6a4f..00000000 Binary files a/libraries/drag-sort-listview/demo/res/drawable-mdpi/drag.9.png and /dev/null differ diff --git a/libraries/drag-sort-listview/demo/res/drawable-mdpi/dslv_launcher.png b/libraries/drag-sort-listview/demo/res/drawable-mdpi/dslv_launcher.png deleted file mode 100644 index 7866ce83..00000000 Binary files a/libraries/drag-sort-listview/demo/res/drawable-mdpi/dslv_launcher.png and /dev/null differ diff --git a/libraries/drag-sort-listview/demo/res/drawable-xhdpi/dslv_launcher.png b/libraries/drag-sort-listview/demo/res/drawable-xhdpi/dslv_launcher.png deleted file mode 100644 index 46fbbbaf..00000000 Binary files a/libraries/drag-sort-listview/demo/res/drawable-xhdpi/dslv_launcher.png and /dev/null differ diff --git a/libraries/drag-sort-listview/demo/res/drawable/bg_handle.xml b/libraries/drag-sort-listview/demo/res/drawable/bg_handle.xml deleted file mode 100644 index 268b1715..00000000 --- a/libraries/drag-sort-listview/demo/res/drawable/bg_handle.xml +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section1.xml b/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section1.xml deleted file mode 100644 index 268b1715..00000000 --- a/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section1.xml +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section1_selector.xml b/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section1_selector.xml deleted file mode 100644 index c688eb5d..00000000 --- a/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section1_selector.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section2.xml b/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section2.xml deleted file mode 100644 index cf7fb3d7..00000000 --- a/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section2.xml +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section2_selector.xml b/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section2_selector.xml deleted file mode 100644 index af383518..00000000 --- a/libraries/drag-sort-listview/demo/res/drawable/bg_handle_section2_selector.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/libraries/drag-sort-listview/demo/res/drawable/drag.9.png b/libraries/drag-sort-listview/demo/res/drawable/drag.9.png deleted file mode 100644 index c90a6a4f..00000000 Binary files a/libraries/drag-sort-listview/demo/res/drawable/drag.9.png and /dev/null differ diff --git a/libraries/drag-sort-listview/demo/res/drawable/section_div.xml b/libraries/drag-sort-listview/demo/res/drawable/section_div.xml deleted file mode 100644 index 7a602f9f..00000000 --- a/libraries/drag-sort-listview/demo/res/drawable/section_div.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - diff --git a/libraries/drag-sort-listview/demo/res/layout/bg_handle_main.xml b/libraries/drag-sort-listview/demo/res/layout/bg_handle_main.xml deleted file mode 100644 index 8d93dcf7..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/bg_handle_main.xml +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/layout/checkable_main.xml b/libraries/drag-sort-listview/demo/res/layout/checkable_main.xml deleted file mode 100644 index 53a34267..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/checkable_main.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - diff --git a/libraries/drag-sort-listview/demo/res/layout/cursor_main.xml b/libraries/drag-sort-listview/demo/res/layout/cursor_main.xml deleted file mode 100644 index 386f08c0..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/cursor_main.xml +++ /dev/null @@ -1,20 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/layout/dslv_fragment_main.xml b/libraries/drag-sort-listview/demo/res/layout/dslv_fragment_main.xml deleted file mode 100644 index b583aaba..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/dslv_fragment_main.xml +++ /dev/null @@ -1,18 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/layout/header_footer.xml b/libraries/drag-sort-listview/demo/res/layout/header_footer.xml deleted file mode 100644 index 456d659c..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/header_footer.xml +++ /dev/null @@ -1,8 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/layout/hetero_main.xml b/libraries/drag-sort-listview/demo/res/layout/hetero_main.xml deleted file mode 100644 index e5b42f30..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/hetero_main.xml +++ /dev/null @@ -1,25 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/layout/jazz_artist_list_item.xml b/libraries/drag-sort-listview/demo/res/layout/jazz_artist_list_item.xml deleted file mode 100644 index d6c8cc3b..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/jazz_artist_list_item.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - diff --git a/libraries/drag-sort-listview/demo/res/layout/launcher.xml b/libraries/drag-sort-listview/demo/res/layout/launcher.xml deleted file mode 100644 index 6ba96398..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/launcher.xml +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/layout/launcher_item.xml b/libraries/drag-sort-listview/demo/res/layout/launcher_item.xml deleted file mode 100644 index 8734d815..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/launcher_item.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - diff --git a/libraries/drag-sort-listview/demo/res/layout/list_item_bg_handle.xml b/libraries/drag-sort-listview/demo/res/layout/list_item_bg_handle.xml deleted file mode 100644 index f85ccccf..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/list_item_bg_handle.xml +++ /dev/null @@ -1,9 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/layout/list_item_checkable.xml b/libraries/drag-sort-listview/demo/res/layout/list_item_checkable.xml deleted file mode 100644 index 0373fc0b..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/list_item_checkable.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - diff --git a/libraries/drag-sort-listview/demo/res/layout/list_item_click_remove.xml b/libraries/drag-sort-listview/demo/res/layout/list_item_click_remove.xml deleted file mode 100644 index ada36f63..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/list_item_click_remove.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - diff --git a/libraries/drag-sort-listview/demo/res/layout/list_item_handle_left.xml b/libraries/drag-sort-listview/demo/res/layout/list_item_handle_left.xml deleted file mode 100644 index 7b8297f1..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/list_item_handle_left.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - diff --git a/libraries/drag-sort-listview/demo/res/layout/list_item_handle_right.xml b/libraries/drag-sort-listview/demo/res/layout/list_item_handle_right.xml deleted file mode 100644 index 527d395c..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/list_item_handle_right.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - diff --git a/libraries/drag-sort-listview/demo/res/layout/list_item_no_handle.xml b/libraries/drag-sort-listview/demo/res/layout/list_item_no_handle.xml deleted file mode 100644 index 396f4508..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/list_item_no_handle.xml +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/layout/list_item_radio.xml b/libraries/drag-sort-listview/demo/res/layout/list_item_radio.xml deleted file mode 100644 index c3e00bca..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/list_item_radio.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - diff --git a/libraries/drag-sort-listview/demo/res/layout/section_div.xml b/libraries/drag-sort-listview/demo/res/layout/section_div.xml deleted file mode 100644 index efe17f28..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/section_div.xml +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/layout/sections_main.xml b/libraries/drag-sort-listview/demo/res/layout/sections_main.xml deleted file mode 100644 index e3094771..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/sections_main.xml +++ /dev/null @@ -1,11 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/layout/test_bed_main.xml b/libraries/drag-sort-listview/demo/res/layout/test_bed_main.xml deleted file mode 100644 index 2d68e5f5..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/test_bed_main.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - diff --git a/libraries/drag-sort-listview/demo/res/layout/warp_main.xml b/libraries/drag-sort-listview/demo/res/layout/warp_main.xml deleted file mode 100644 index 080bff6c..00000000 --- a/libraries/drag-sort-listview/demo/res/layout/warp_main.xml +++ /dev/null @@ -1,26 +0,0 @@ - - diff --git a/libraries/drag-sort-listview/demo/res/menu/mode_menu.xml b/libraries/drag-sort-listview/demo/res/menu/mode_menu.xml deleted file mode 100644 index 9436926d..00000000 --- a/libraries/drag-sort-listview/demo/res/menu/mode_menu.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - diff --git a/libraries/drag-sort-listview/demo/res/values/colors.xml b/libraries/drag-sort-listview/demo/res/values/colors.xml deleted file mode 100644 index a7d30888..00000000 --- a/libraries/drag-sort-listview/demo/res/values/colors.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - #33b5e5 - #0099cc - #ff4444 - #adadad - #ffffff - #000000 - #a0a0a0 - diff --git a/libraries/drag-sort-listview/demo/res/values/dimens.xml b/libraries/drag-sort-listview/demo/res/values/dimens.xml deleted file mode 100644 index b6a1706e..00000000 --- a/libraries/drag-sort-listview/demo/res/values/dimens.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - 67dp - 20dp - diff --git a/libraries/drag-sort-listview/demo/res/values/ids.xml b/libraries/drag-sort-listview/demo/res/values/ids.xml deleted file mode 100644 index a3354350..00000000 --- a/libraries/drag-sort-listview/demo/res/values/ids.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/libraries/drag-sort-listview/demo/res/values/strings.xml b/libraries/drag-sort-listview/demo/res/values/strings.xml deleted file mode 100644 index c1c3deb6..00000000 --- a/libraries/drag-sort-listview/demo/res/values/strings.xml +++ /dev/null @@ -1,306 +0,0 @@ - - - Drag-Sort Demos - - Basic usage playground - Heteroheight - Warp - Background handle - Sections - CursorAdapter - Multiple-choice mode - Single-choice mode - - - - Use the menu to adjust settings related to item - removal and drag initiation. These options are - provided by the DragSortController class. - - - Demonstrates (tests) drag-sorting when list items - have varying heights. - - - Demonstrates drag-scroll customization; long lists - need fast scrolling. - - - Simple DragSortController customization. In this example, - the drag handle is a background drawable; therefore, the - drag handle hit detection mechanism needs modification. - Also, the floating View is given some flavor. - - - Demonstrates floating View control from a custom - FloatViewManager. Restrict item drags to list sections. - - - Demonstrates usage of the DragSortCursorAdapter class, - which abstracts drag-sorts with a remapping of Cursor - positions to ListView positions. - - - Uses Checkable list items in multiple-choice mode. - - - Uses Checkable list items to allow for selectable radio - buttons in single-choice mode. - - - OK - Cancel - Remove modes - Start-drag modes - Enable/Disable - Add header - Add footer - - Click remove - Fling remove - - - On down - On drag - On long press - - - Enable drag - Enable sort - Enable remove - - - Brad Mehldau - Joshua Redman - Chick Corea - Kurt Rosenwinkel - Miles Davis - Wayne Shorter - Michael Brecker - Herbie Hancock - Joe Zawinul - Brian Blade - Jeff Ballard - Larry Grenadier - Keith Jarrett - McCoy Tyner - Stephon Harris - Mark Turner - - - Largo, Art of the Trio 1-4, Highway Rider, Songs - Elastic, Momentum, Mood Swing, Back East - Light as a Feather, Akoustic Band, My Spanish Heart - Deep Song, Heartcore, Our Secret World, Reflections, The Remedy: Live at the Village - Vanguard, The Enemies of Energy, The Next Step - - - - - Afghanistan - Albania - Algeria - American Samoa - Andorra - Angola - Anguilla - Antigua and Barbuda - Argentina - Armenia - Australia - Austria - Azerbajan - Bahamas - Bahrain - Bangladesh - Barbados - Belarus - Belgium - Belize - Benin - Bermuda - Bhutan - Bolivia - Bosnia and Herzegovina - Botswana - Brazil - Brunei Darussalam - Bulgaria - Burkina Faso - Burundi - Cambodia - Cameroon - Canada - Chile - China - Colombia - Costa Rica - Cuba - Cyprus - Czech Republic - Democratic Republic Congo - Denmark - Djibouti - Dominican Republic - East Timor - Ecuador - Egypt - El Salvador - England - Eritrea - Estonia - Ethiopia - Faroe Islands - Fiji - Finland - France - French Polynesia - Gambia - Georgia (Sakartvelo) - Germany - Gabon - Ghana - Greece - Greenland - Kalaallit Nunaat - Grenada - Gouadeloupe - Guam - Guatemala - Guernsey - Guyana - Guyane - Haiti - Honduras - Hong Kong - Hrvatska (Croatia) - Hungary - Iceland - India - Indonesia - Iran - Iraq - Ireland - Israel - Italy - Jamaica - Japan - Jordan - Kazakhstan - Kenya - Korea Republic - Kosovo - Kurdistan - Kuwait - Kyrgyzstan - Laos - Latvia - Lebanon - Lesotho - Liberia - Libyan Arab Jamahiriya - Liechtenstein - Lithuania - Luxembourg - Macau - Macedonia - Malawi - Malaysia - Mali - Malta - Marshall Islands - Mauritania - Martinique - Mauritius - Mexico - Micronesia - Moldova - Monaco - Mongolia - Morocco - Mozambique - Namibia - Nepal - Netherlands - Netherlands Antilles - New Caledonia - New Zealand (Aotearoa) - Nicaragua - Nigeria - Niue - Norfolk Island - Northern Ireland - Northern Mariana Islands - Norway - Oman - Pakistan - Palau - Palestina - Panama - Papua New Guinea - Paraguay - Peru - Philippines - Portugal - Puerto Rico - Qatar - Reunion - Romania - Russian Federation (AsianPart) - Russian Federation (European Part) - Rwanda - Saint Kitts and Nevis - Saint Vincent and the Grenadines - Samoa (American Samoa) - Samoa (Western Samoa) - San Marino - Saudi Arabia - Scotland - Senegal - Seychelles - Sierra Leone - Singapore - Slovakia - Slovenia - Solomon Islands - Somalia - Somaliland - South Africa - Spain - Sri Lanka - Sudan - Suriname - Svalbard and Jan Mayen - Swaziland - Sweden - Switzerland - Syrian Arab Republic - Taiwan - Tanzania - Thailand - Tibet - Togo - Tonga - Trinidad and Tobago - Tunisia - Turkey - Turkmenistan - Turks and Caicos Islands - Uganda - Ukraine - United Arab Emirates - United Kingdom - Uruguay - USA - Uzbekistan - Vatican City State - Holy See - Venezuela - Viet Nam - Virgin Islands (British) - Virgin Islands (U.S.) - Wales - Yemen - Yugoslavia - Zambia - Zimbabwe - - diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/ArbItemSizeDSLV.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/ArbItemSizeDSLV.java deleted file mode 100644 index 8b154ded..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/ArbItemSizeDSLV.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.app.ListActivity; -import android.os.Bundle; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TextView; - -import com.mobeta.android.dslv.DragSortListView; - -import java.util.ArrayList; -import java.util.List; - - -public class ArbItemSizeDSLV extends ListActivity { - - private JazzAdapter mAdapter; - - private final DragSortListView.DropListener mDropListener = - new DragSortListView.DropListener() { - @Override - public void drop(int from, int to) { - JazzArtist item = mAdapter.getItem(from); - - mAdapter.remove(item); - mAdapter.insert(item, to); - } - }; - - private final DragSortListView.RemoveListener mRemoveListener = - new DragSortListView.RemoveListener() { - @Override - public void remove(int which) { - mAdapter.remove(mAdapter.getItem(which)); - } - }; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.hetero_main); - - DragSortListView lv = (DragSortListView) getListView(); - - lv.setDropListener(mDropListener); - lv.setRemoveListener(mRemoveListener); - - String[] artistNames = getResources().getStringArray(R.array.jazz_artist_names); - String[] artistAlbums = getResources().getStringArray(R.array.jazz_artist_albums); - - int len = artistAlbums.length; - List artists = new ArrayList(len); - JazzArtist ja; - for (int i = 0; i < len; ++i) { - ja = new JazzArtist(); - ja.name = artistNames[i]; - if (i < artistAlbums.length) { - ja.albums = artistAlbums[i]; - } else { - ja.albums = "No albums listed"; - } - artists.add(ja); - } - - mAdapter = new JazzAdapter(artists); - - setListAdapter(mAdapter); - - } - - private class JazzArtist { - public String name; - public String albums; - - @Override - public String toString() { - return name; - } - } - - private class ViewHolder { - public TextView albumsView; - } - - private class JazzAdapter extends ArrayAdapter { - - public JazzAdapter(List artists) { - super(ArbItemSizeDSLV.this, R.layout.jazz_artist_list_item, - R.id.artist_name_textview, artists); - } - - public View getView(int position, View convertView, ViewGroup parent) { - View v = super.getView(position, convertView, parent); - - if (v != convertView && v != null) { - ViewHolder holder = new ViewHolder(); - - holder.albumsView = (TextView) v.findViewById(R.id.artist_albums_textview); - - v.setTag(holder); - } - - String albums = getItem(position).albums; - - ViewHolder holder = (ViewHolder) v.getTag(); - holder.albumsView.setText(albums); - - return v; - } - } - -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/BGHandle.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/BGHandle.java deleted file mode 100644 index ec703ab8..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/BGHandle.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.os.Bundle; -import android.support.v4.app.FragmentActivity; - -public class BGHandle extends FragmentActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.bg_handle_main); - } - -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/CheckableLinearLayout.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/CheckableLinearLayout.java deleted file mode 100644 index 8d272dc4..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/CheckableLinearLayout.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.content.Context; -import android.util.AttributeSet; -import android.widget.Checkable; -import android.widget.LinearLayout; - -public class CheckableLinearLayout extends LinearLayout implements Checkable { - - private static final int CHECKABLE_CHILD_INDEX = 1; - private Checkable child; - - public CheckableLinearLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - child = (Checkable) getChildAt(CHECKABLE_CHILD_INDEX); - } - - @Override - public boolean isChecked() { - return child.isChecked(); - } - - @Override - public void setChecked(boolean checked) { - child.setChecked(checked); - } - - @Override - public void toggle() { - child.toggle(); - } - -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/CursorDSLV.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/CursorDSLV.java deleted file mode 100644 index dcb15b6f..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/CursorDSLV.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.content.Context; -import android.database.Cursor; -import android.database.MatrixCursor; -import android.os.Bundle; -import android.support.v4.app.FragmentActivity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Toast; - -import com.mobeta.android.dslv.DragSortListView; -import com.mobeta.android.dslv.SimpleDragSortCursorAdapter; - -public class CursorDSLV extends FragmentActivity { - - private SimpleDragSortCursorAdapter adapter; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.cursor_main); - - String[] cols = { "name" }; - int[] ids = { R.id.text }; - adapter = new MAdapter(this, - R.layout.list_item_click_remove, null, cols, ids, 0); - - DragSortListView dslv = (DragSortListView) findViewById(android.R.id.list); - dslv.setAdapter(adapter); - - // build a cursor from the String array - MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "name" }); - String[] artistNames = getResources().getStringArray(R.array.jazz_artist_names); - for (int i = 0; i < artistNames.length; i++) { - cursor.newRow() - .add(i) - .add(artistNames[i]); - } - adapter.changeCursor(cursor); - } - - private class MAdapter extends SimpleDragSortCursorAdapter { - private final Context mContext; - - public MAdapter(Context ctxt, int rmid, Cursor c, String[] cols, int[] ids, int something) { - super(ctxt, rmid, c, cols, ids, something); - mContext = ctxt; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - View v = super.getView(position, convertView, parent); - View tv = v.findViewById(R.id.text); - tv.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Toast.makeText(mContext, "text clicked", Toast.LENGTH_SHORT).show(); - } - }); - return v; - } - } -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DSLVFragment.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DSLVFragment.java deleted file mode 100644 index 2ab76e03..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DSLVFragment.java +++ /dev/null @@ -1,184 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.app.Activity; -import android.os.Bundle; -import android.support.v4.app.ListFragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TextView; - -import com.mobeta.android.dslv.DragSortController; -import com.mobeta.android.dslv.DragSortListView; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - - -public class DSLVFragment extends ListFragment { - - private ArrayAdapter mAdapter; - - private final DragSortListView.DropListener mDropListener = - new DragSortListView.DropListener() { - @Override - public void drop(int from, int to) { - if (from != to) { - String item = mAdapter.getItem(from); - mAdapter.remove(item); - mAdapter.insert(item, to); - } - } - }; - - private final DragSortListView.RemoveListener mRemoveListener = - new DragSortListView.RemoveListener() { - @Override - public void remove(int which) { - mAdapter.remove(mAdapter.getItem(which)); - } - }; - - private DragSortListView mDslv; - private DragSortController mController; - - public int dragStartMode = DragSortController.ON_DOWN; - public boolean removeEnabled = false; - public int removeMode = DragSortController.FLING_REMOVE; - public boolean sortEnabled = true; - public boolean dragEnabled = true; - - public static DSLVFragment newInstance(int headers, int footers) { - DSLVFragment f = new DSLVFragment(); - - Bundle args = new Bundle(); - args.putInt("headers", headers); - args.putInt("footers", footers); - f.setArguments(args); - - return f; - } - - public DSLVFragment() { - super(); - } - - protected int getLayout() { - // this DSLV xml declaration does not call for the use - // of the default DragSortController; therefore, - // DSLVFragment has a buildController() method. - return R.layout.dslv_fragment_main; - } - - /** - * Return list item layout resource passed to the ArrayAdapter. - */ - protected int getItemLayout() { - /*if (removeMode == DragSortController.FLING_LEFT_REMOVE || removeMode == DragSortController.SLIDE_LEFT_REMOVE) { - 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; - } - } - - public DragSortController getController() { - return mController; - } - - /** - * Called from DSLVFragment.onActivityCreated(). Override to - * set a different mAdapter. - */ - protected void setListAdapter() { - String[] array = getResources().getStringArray(R.array.jazz_artist_names); - List list = new ArrayList(Arrays.asList(array)); - - mAdapter = new ArrayAdapter(getActivity(), getItemLayout(), R.id.text, list); - setListAdapter(mAdapter); - } - - /** - * Called in onCreateView. Override this to provide a custom - * DragSortController. - */ - protected DragSortController buildController(DragSortListView dslv) { - // defaults are - // dragStartMode = onDown - // 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); - controller.setRemoveMode(removeMode); - return controller; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - mDslv = (DragSortListView) inflater.inflate(getLayout(), container, false); - - mController = buildController(mDslv); - mDslv.setFloatViewManager(mController); - mDslv.setOnTouchListener(mController); - mDslv.setDragEnabled(dragEnabled); - - return mDslv; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mDslv = (DragSortListView) getListView(); - - mDslv.setDropListener(mDropListener); - mDslv.setRemoveListener(mRemoveListener); - - Bundle args = getArguments(); - int headers = 0; - int footers = 0; - if (args != null) { - headers = args.getInt("headers", 0); - footers = args.getInt("footers", 0); - } - - for (int i = 0; i < headers; i++) { - addHeader(getActivity(), mDslv); - } - for (int i = 0; i < footers; i++) { - addFooter(getActivity(), mDslv); - } - - setListAdapter(); - } - - - public static void addHeader(Activity activity, DragSortListView dslv) { - LayoutInflater inflater = activity.getLayoutInflater(); - int count = dslv.getHeaderViewsCount(); - - TextView header = (TextView) inflater.inflate(R.layout.header_footer, null); - header.setText("Header #" + (count + 1)); - - dslv.addHeaderView(header, null, false); - } - - public static void addFooter(Activity activity, DragSortListView dslv) { - LayoutInflater inflater = activity.getLayoutInflater(); - int count = dslv.getFooterViewsCount(); - - TextView footer = (TextView) inflater.inflate(R.layout.header_footer, null); - footer.setText("Footer #" + (count + 1)); - - dslv.addFooterView(footer, null, false); - } - -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DSLVFragmentBGHandle.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DSLVFragmentBGHandle.java deleted file mode 100644 index 62804c70..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DSLVFragmentBGHandle.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ListAdapter; - -import com.mobeta.android.dslv.DragSortController; -import com.mobeta.android.dslv.DragSortListView; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class DSLVFragmentBGHandle extends DSLVFragment { - - public DSLVFragmentBGHandle() { - super(); - } - - @Override - public int getItemLayout() { - return R.layout.list_item_bg_handle; - } - - @Override - protected void setListAdapter() { - String[] array = getResources().getStringArray(R.array.jazz_artist_names); - ArrayList list = new ArrayList(Arrays.asList(array)); - setListAdapter(new MyAdapter(list)); - } - - @Override - protected DragSortController buildController(DragSortListView dslv) { - return new MyDSController(dslv); - } - - - private class MyAdapter extends ArrayAdapter { - - public MyAdapter(List artists) { - super(getActivity(), getItemLayout(), R.id.text, artists); - } - - public View getView(int position, View convertView, ViewGroup parent) { - View v = super.getView(position, convertView, parent); - v.getBackground().setLevel(3000); - return v; - } - } - - private class MyDSController extends DragSortController { - - DragSortListView mDslv; - - public MyDSController(DragSortListView dslv) { - super(dslv); - setDragHandleId(R.id.text); - mDslv = dslv; - } - - @Override - public View onCreateFloatView(int position) { - View v = getListAdapter().getView(position, null, mDslv); - v.getBackground().setLevel(10000); - return v; - } - - @Override - public void onDestroyFloatView(View floatView) { - //do nothing; block super from crashing - } - - @Override - public int startDragPosition(MotionEvent ev) { - int res = super.dragHandleHitPosition(ev); - int width = mDslv.getWidth(); - - if ((int) ev.getX() < width / 3) { - return res; - } else { - return DragSortController.MISS; - } - } - } - - - -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DSLVFragmentClicks.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DSLVFragmentClicks.java deleted file mode 100644 index 75d9aad6..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DSLVFragmentClicks.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.os.Bundle; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ListView; -import android.widget.Toast; - -public class DSLVFragmentClicks extends DSLVFragment { - - public static DSLVFragmentClicks newInstance(int headers, int footers) { - DSLVFragmentClicks f = new DSLVFragmentClicks(); - - Bundle args = new Bundle(); - args.putInt("headers", headers); - args.putInt("footers", footers); - f.setArguments(args); - - return f; - } - - public DSLVFragmentClicks() { - super(); - } - - @Override - public void onActivityCreated(Bundle savedState) { - super.onActivityCreated(savedState); - - ListView lv = getListView(); - lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView arg0, View arg1, int arg2, - long arg3) { - String message = String.format("Clicked item %d", arg2); - Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show(); - - } - }); - lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView arg0, View arg1, int arg2, - long arg3) { - String message = String.format("Long-clicked item %d", arg2); - Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show(); - return true; - } - }); - } -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DragInitModeDialog.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DragInitModeDialog.java deleted file mode 100644 index a3668b2b..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/DragInitModeDialog.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; - -import com.mobeta.android.dslv.DragSortController; - -/** - * Sets drag init mode on DSLV controller passed into ctor. - */ -public class DragInitModeDialog extends DialogFragment { - - private static final String EXTRA_DRAG_INIT_MODE = "drag_init_mode"; - - private int mDragInitMode; - - private DragOkListener mListener; - - public static DragInitModeDialog newInstance(int dragInitMode) { - Bundle args = new Bundle(); - args.putInt(EXTRA_DRAG_INIT_MODE, dragInitMode); - - DragInitModeDialog frag = new DragInitModeDialog(); - frag.setArguments(args); - return frag; - } - - public DragInitModeDialog() { - super(); - } - - public interface DragOkListener { - public void onDragOkClick(int removeMode); - } - - public void setDragOkListener(DragOkListener l) { - mListener = l; - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - mDragInitMode = getArguments().getInt(EXTRA_DRAG_INIT_MODE, DragSortController.ON_DOWN); - - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - // Set the dialog title - builder.setTitle(R.string.select_remove_mode) - .setSingleChoiceItems(R.array.drag_init_mode_labels, mDragInitMode, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - mDragInitMode = which; - } - }) - // Set the action buttons - .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - if (mListener != null) { - mListener.onDragOkClick(mDragInitMode); - } - } - }) - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - } - }); - - return builder.create(); - } -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/EnablesDialog.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/EnablesDialog.java deleted file mode 100644 index 8d0ef681..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/EnablesDialog.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; - -public class EnablesDialog extends DialogFragment { - - private static final String EXTRA_ENABLED_FLAGS = "enabled_flags"; - - private boolean[] mEnabled; - - private EnabledOkListener mListener; - - public static EnablesDialog newInstance(boolean drag, boolean sort, boolean remove) { - Bundle args = new Bundle(); - args.putBooleanArray(EXTRA_ENABLED_FLAGS, new boolean[] { drag, sort, remove }); - - EnablesDialog frag = new EnablesDialog(); - frag.setArguments(args); - return frag; - } - - public EnablesDialog() { - super(); - } - - public interface EnabledOkListener { - void onEnabledOkClick(boolean drag, boolean sort, boolean remove); - } - - public void setEnabledOkListener(EnabledOkListener l) { - mListener = l; - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - mEnabled = getArguments().getBooleanArray(EXTRA_ENABLED_FLAGS); - if (mEnabled == null) { - mEnabled = new boolean[] { true, true, false }; - } - - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - // Set the dialog title - builder.setTitle(R.string.select_remove_mode) - .setMultiChoiceItems(R.array.enables_labels, mEnabled, - new DialogInterface.OnMultiChoiceClickListener() { - @Override - public void onClick(DialogInterface dialog, int which, boolean isChecked) { - mEnabled[which] = isChecked; - } - }) - // Set the action buttons - .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - if (mListener != null) { - mListener.onEnabledOkClick(mEnabled[0], mEnabled[1], mEnabled[2]); - } - } - }) - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - } - }); - - return builder.create(); - } -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/Launcher.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/Launcher.java deleted file mode 100644 index fe0ef0da..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/Launcher.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.app.ListActivity; -import android.content.Intent; -import android.content.pm.ActivityInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.TextView; - -import java.util.ArrayList; -import java.util.Arrays; - - -public class Launcher extends ListActivity { - - private ArrayList mActivities = null; - - private String[] mActTitles; - private String[] mActDescs; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.launcher); - - try { - PackageInfo pi = getPackageManager().getPackageInfo( - "com.mobeta.android.demodslv", PackageManager.GET_ACTIVITIES); - - mActivities = new ArrayList(Arrays.asList(pi.activities)); - String ourName = getClass().getName(); - for (int i = 0; i < mActivities.size(); ++i) { - if (ourName.equals(mActivities.get(i).name)) { - mActivities.remove(i); - break; - } - } - } catch (PackageManager.NameNotFoundException e) { - // Do nothing. Adapter will be empty. - } - - mActTitles = getResources().getStringArray(R.array.activity_titles); - mActDescs = getResources().getStringArray(R.array.activity_descs); - - setListAdapter(new MyAdapter()); - } - - @Override - protected void onListItemClick(ListView l, View v, int position, long id) { - Intent intent = new Intent(); - intent.setClassName(this, mActivities.get(position).name); - startActivity(intent); - } - - private class MyAdapter extends ArrayAdapter { - MyAdapter() { - super(Launcher.this, R.layout.launcher_item, R.id.activity_title, mActivities); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - View v = super.getView(position, convertView, parent); - - TextView title = (TextView) v.findViewById(R.id.activity_title); - TextView desc = (TextView) v.findViewById(R.id.activity_desc); - - title.setText(mActTitles[position]); - desc.setText(mActDescs[position]); - return v; - } - - } - -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/MultipleChoiceListView.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/MultipleChoiceListView.java deleted file mode 100644 index afdad493..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/MultipleChoiceListView.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.app.ListActivity; -import android.os.Bundle; -import android.widget.ArrayAdapter; - -import com.mobeta.android.dslv.DragSortListView; -import com.mobeta.android.dslv.DragSortListView.RemoveListener; - -import java.util.ArrayList; -import java.util.Arrays; - - -public class MultipleChoiceListView extends ListActivity { - - private ArrayAdapter adapter; - - private final DragSortListView.DropListener mDropListener = - new DragSortListView.DropListener() { - @Override - public void drop(int from, int to) { - if (from != to) { - DragSortListView list = getListView(); - String item = adapter.getItem(from); - adapter.remove(item); - adapter.insert(item, to); - list.moveCheckState(from, to); - } - } - }; - - private final RemoveListener mRemoveListener = - new DragSortListView.RemoveListener() { - @Override - public void remove(int which) { - DragSortListView list = getListView(); - String item = adapter.getItem(which); - adapter.remove(item); - list.removeCheckState(which); - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.checkable_main); - - String[] array = getResources().getStringArray(R.array.jazz_artist_names); - ArrayList arrayList = new ArrayList(Arrays.asList(array)); - - adapter = new ArrayAdapter(this, R.layout.list_item_checkable, R.id.text, arrayList); - - setListAdapter(adapter); - - DragSortListView list = getListView(); - list.setDropListener(mDropListener); - list.setRemoveListener(mRemoveListener); - } - - @Override - public DragSortListView getListView() { - return (DragSortListView) super.getListView(); - } - -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/RemoveModeDialog.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/RemoveModeDialog.java deleted file mode 100644 index 097ceac7..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/RemoveModeDialog.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; - -import com.mobeta.android.dslv.DragSortController; - -/** - * Simply passes remove mode back to OnOkListener - */ -public class RemoveModeDialog extends DialogFragment { - - private static final String EXTRA_REMOVE_MODE = "remove_mode"; - - private int mRemoveMode; - - private RemoveOkListener mListener; - - public static RemoveModeDialog newInstance(int removeMode) { - Bundle args = new Bundle(); - args.putInt(EXTRA_REMOVE_MODE, removeMode); - - RemoveModeDialog frag = new RemoveModeDialog(); - frag.setArguments(args); - return frag; - } - - public RemoveModeDialog() { - super(); - } - - public interface RemoveOkListener { - void onRemoveOkClick(int removeMode); - } - - public void setRemoveOkListener(RemoveOkListener l) { - mListener = l; - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - mRemoveMode = getArguments().getInt(EXTRA_REMOVE_MODE, DragSortController.FLING_REMOVE); - - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - // Set the dialog title - builder.setTitle(R.string.select_remove_mode) - .setSingleChoiceItems(R.array.remove_mode_labels, mRemoveMode, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - mRemoveMode = which; - } - }) - // Set the action buttons - .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - if (mListener != null) { - mListener.onRemoveOkClick(mRemoveMode); - } - } - }) - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - } - }); - - return builder.create(); - } -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/Sections.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/Sections.java deleted file mode 100644 index b6c8b328..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/Sections.java +++ /dev/null @@ -1,259 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.app.ListActivity; -import android.content.Context; -import android.graphics.Point; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.TextView; - -import com.mobeta.android.dslv.DragSortController; -import com.mobeta.android.dslv.DragSortListView; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class Sections extends ListActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.sections_main); - - DragSortListView dslv = (DragSortListView) getListView(); - - // get jazz artist names and make adapter - String[] array = getResources().getStringArray(R.array.jazz_artist_names); - List list = new ArrayList(Arrays.asList(array)); - SectionAdapter adapter = new SectionAdapter(this, list); - dslv.setDropListener(adapter); - - // make and set controller on dslv - SectionController c = new SectionController(dslv, adapter); - dslv.setFloatViewManager(c); - dslv.setOnTouchListener(c); - - // pass it to the ListActivity - setListAdapter(adapter); - } - - private class SectionController extends DragSortController { - - private int mPos; - private int mDivPos; - - private SectionAdapter mAdapter; - - DragSortListView mDslv; - - public SectionController(DragSortListView dslv, SectionAdapter adapter) { - super(dslv, R.id.text, DragSortController.ON_DOWN, 0); - setRemoveEnabled(false); - mDslv = dslv; - mAdapter = adapter; - mDivPos = adapter.getDivPosition(); - } - - @Override - public int startDragPosition(MotionEvent ev) { - int res = super.dragHandleHitPosition(ev); - if (res == mDivPos) { - return DragSortController.MISS; - } - - int width = mDslv.getWidth(); - - if ((int) ev.getX() < width / 3) { - return res; - } else { - return DragSortController.MISS; - } - } - - @Override - public View onCreateFloatView(int position) { - mPos = position; - - View v = mAdapter.getView(position, null, mDslv); - if (position < mDivPos) { - v.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_handle_section1)); - } else { - v.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_handle_section2)); - } - v.getBackground().setLevel(10000); - return v; - } - - private int origHeight = -1; - - @Override - public void onDragFloatView(View floatView, Point floatPoint, Point touchPoint) { - final int first = mDslv.getFirstVisiblePosition(); - final int lvDivHeight = mDslv.getDividerHeight(); - - if (origHeight == -1) { - origHeight = floatView.getHeight(); - } - - View div = mDslv.getChildAt(mDivPos - first); - - if (touchPoint.x > mDslv.getWidth() / 2) { - float scale = touchPoint.x - mDslv.getWidth() / 2; - scale /= (float) (mDslv.getWidth() / 5); - ViewGroup.LayoutParams lp = floatView.getLayoutParams(); - lp.height = Math.max(origHeight, (int) (scale * origHeight)); - Log.d("mobeta", "setting height "+lp.height); - floatView.setLayoutParams(lp); - } - - if (div != null) { - if (mPos > mDivPos) { - // don't allow floating View to go above - // section divider - final int limit = div.getBottom() + lvDivHeight; - if (floatPoint.y < limit) { - floatPoint.y = limit; - } - } else { - // don't allow floating View to go below - // section divider - final int limit = div.getTop() - lvDivHeight - floatView.getHeight(); - if (floatPoint.y > limit) { - floatPoint.y = limit; - } - } - } - } - - @Override - public void onDestroyFloatView(View floatView) { - //do nothing; block super from crashing - } - - } - - private class SectionAdapter extends BaseAdapter implements DragSortListView.DropListener { - - private final static int SECTION_DIV = 0; - private final static int SECTION_ONE = 1; - private final static int SECTION_TWO = 2; - - private List mData; - - private int mDivPos; - - private final LayoutInflater mInflater; - - public SectionAdapter(Context context, List names) { - super(); - mInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); - mData = names; - mDivPos = names.size() / 2; - } - - @Override - public void drop(int from, int to) { - if (from != to) { - String data = mData.remove(dataPosition(from)); - mData.add(dataPosition(to), data); - notifyDataSetChanged(); - } - } - - @Override - public int getCount() { - return mData.size() + 1; - } - - @Override - public boolean areAllItemsEnabled() { - return false; - } - - @Override - public boolean isEnabled(int position) { - return position != mDivPos; - } - - public int getDivPosition() { - return mDivPos; - } - - @Override - public int getViewTypeCount() { - return 3; - } - - @Override - public String getItem(int position) { - if (position == mDivPos) { - return "Something"; - } else { - return mData.get(dataPosition(position)); - } - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public int getItemViewType(int position) { - if (position == mDivPos) { - return SECTION_DIV; - } else if (position < mDivPos) { - return SECTION_ONE; - } else { - return SECTION_TWO; - } - } - - private int dataPosition(int position) { - return position > mDivPos ? position - 1 : position; - } - - public Drawable getBGDrawable(int type) { - Drawable d; - if (type == SECTION_ONE) { - d = getResources().getDrawable(R.drawable.bg_handle_section1_selector); - } else { - d = getResources().getDrawable(R.drawable.bg_handle_section2_selector); - } - d.setLevel(3000); - return d; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - final int type = getItemViewType(position); - - View v = null; - if (convertView != null) { - Log.d("mobeta", "using convertView"); - v = convertView; - } else if (type != SECTION_DIV) { - Log.d("mobeta", "inflating normal item"); - v = mInflater.inflate(R.layout.list_item_bg_handle, parent, false); - v.setBackgroundDrawable(getBGDrawable(type)); - } else { - Log.d("mobeta", "inflating section divider"); - v = mInflater.inflate(R.layout.section_div, parent, false); - } - - if (type != SECTION_DIV) { - // bind data - ((TextView) v).setText(mData.get(dataPosition(position))); - } - - return v; - } - } -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/SingleChoiceListView.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/SingleChoiceListView.java deleted file mode 100644 index 8f9b74e3..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/SingleChoiceListView.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.mobeta.android.demodslv; - -import java.util.ArrayList; -import java.util.Arrays; - -import android.app.ListActivity; -import android.os.Build; -import android.os.Bundle; -import android.util.Log; -import android.widget.ArrayAdapter; -import android.widget.ListView; - -import com.mobeta.android.dslv.DragSortListView; - - -public class SingleChoiceListView extends ListActivity { - private ArrayAdapter adapter; - - private DragSortListView.DropListener onDrop = - new DragSortListView.DropListener() { - @Override - public void drop(int from, int to) { - if (from != to) { - DragSortListView list = getListView(); - String item = adapter.getItem(from); - adapter.remove(item); - adapter.insert(item, to); - list.moveCheckState(from, to); - Log.d("DSLV", "Selected item is " + list.getCheckedItemPosition()); - } - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.checkable_main); - - String[] array = getResources().getStringArray(R.array.jazz_artist_names); - ArrayList arrayList = new ArrayList(Arrays.asList(array)); - - adapter = new ArrayAdapter(this, R.layout.list_item_radio, R.id.text, arrayList); - - setListAdapter(adapter); - - DragSortListView list = getListView(); - list.setDropListener(onDrop); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - } - } - - @Override - public DragSortListView getListView() { - return (DragSortListView) super.getListView(); - } - -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/TestBedDSLV.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/TestBedDSLV.java deleted file mode 100644 index dceb5d3a..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/TestBedDSLV.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentTransaction; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; - -import com.mobeta.android.dslv.DragSortController; -import com.mobeta.android.dslv.DragSortListView; - - -public class TestBedDSLV extends FragmentActivity implements RemoveModeDialog.RemoveOkListener, - DragInitModeDialog.DragOkListener, EnablesDialog.EnabledOkListener { - - private static final String TAG_DSLV_FRAGMENT = "dslv_fragment"; - - private int mNumHeaders = 0; - private int mNumFooters = 0; - - private int mDragStartMode = DragSortController.ON_DRAG; - private boolean mRemoveEnabled = true; - private int mRemoveMode = DragSortController.FLING_REMOVE; - private boolean mSortEnabled = true; - private boolean mDragEnabled = true; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.test_bed_main); - - FragmentManager fm = getSupportFragmentManager(); - if (fm.findFragmentByTag(TAG_DSLV_FRAGMENT) == null) { - fm.beginTransaction() - .add(R.id.test_bed, getNewDslvFragment(), TAG_DSLV_FRAGMENT) - .commit(); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.mode_menu, menu); - return true; - } - - @Override - public void onRemoveOkClick(int removeMode) { - if (removeMode != mRemoveMode) { - mRemoveMode = removeMode; - getSupportFragmentManager().beginTransaction() - .replace(R.id.test_bed, getNewDslvFragment(), TAG_DSLV_FRAGMENT) - .commit(); - } - } - - @Override - public void onDragOkClick(int dragStartMode) { - mDragStartMode = dragStartMode; - DSLVFragment f = - (DSLVFragment) getSupportFragmentManager().findFragmentByTag(TAG_DSLV_FRAGMENT); - f.getController().setDragInitMode(dragStartMode); - } - - @Override - public void onEnabledOkClick(boolean drag, boolean sort, boolean remove) { - mSortEnabled = sort; - mRemoveEnabled = remove; - mDragEnabled = drag; - DSLVFragment f = - (DSLVFragment) getSupportFragmentManager().findFragmentByTag(TAG_DSLV_FRAGMENT); - DragSortListView dslv = (DragSortListView) f.getListView(); - f.getController().setRemoveEnabled(remove); - f.getController().setSortEnabled(sort); - dslv.setDragEnabled(drag); - } - - private Fragment getNewDslvFragment() { - DSLVFragmentClicks f = DSLVFragmentClicks.newInstance(mNumHeaders, mNumFooters); - f.removeMode = mRemoveMode; - f.removeEnabled = mRemoveEnabled; - f.dragStartMode = mDragStartMode; - f.sortEnabled = mSortEnabled; - f.dragEnabled = mDragEnabled; - return f; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.select_remove_mode: - RemoveModeDialog rdialog = RemoveModeDialog.newInstance(mRemoveMode); - rdialog.setRemoveOkListener(this); - rdialog.show(getSupportFragmentManager(), "RemoveMode"); - return true; - case R.id.select_drag_init_mode: - DragInitModeDialog ddialog = DragInitModeDialog.newInstance(mDragStartMode); - ddialog.setDragOkListener(this); - ddialog.show(getSupportFragmentManager(), "DragInitMode"); - return true; - case R.id.select_enables: - EnablesDialog edialog = - EnablesDialog.newInstance(mDragEnabled, mSortEnabled, mRemoveEnabled); - edialog.setEnabledOkListener(this); - edialog.show(getSupportFragmentManager(), "Enables"); - return true; - case R.id.add_header: - mNumHeaders++; - getSupportFragmentManager().beginTransaction() - .replace(R.id.test_bed, getNewDslvFragment(), TAG_DSLV_FRAGMENT) - .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) - .commit(); - return true; - case R.id.add_footer: - mNumFooters++; - getSupportFragmentManager().beginTransaction() - .replace(R.id.test_bed, getNewDslvFragment(), TAG_DSLV_FRAGMENT) - .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) - .commit(); - return true; - default: - return super.onOptionsItemSelected(item); - } - } -} diff --git a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/WarpDSLV.java b/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/WarpDSLV.java deleted file mode 100644 index 04dd85fe..00000000 --- a/libraries/drag-sort-listview/demo/src/com/mobeta/android/demodslv/WarpDSLV.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.mobeta.android.demodslv; - -import android.app.ListActivity; -import android.os.Bundle; -import android.widget.ArrayAdapter; - -import com.mobeta.android.dslv.DragSortListView; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class WarpDSLV extends ListActivity { - - private ArrayAdapter mAdapter; - - private final DragSortListView.DropListener mDropListener = - new DragSortListView.DropListener() { - @Override - public void drop(int from, int to) { - String item = mAdapter.getItem(from); - - mAdapter.notifyDataSetChanged(); - mAdapter.remove(item); - mAdapter.insert(item, to); - } - }; - - private final DragSortListView.RemoveListener mRemoveListener = - new DragSortListView.RemoveListener() { - @Override - public void remove(int which) { - mAdapter.remove(mAdapter.getItem(which)); - } - }; - - private final DragSortListView.DragScrollProfile mDragScrollProfile = - new DragSortListView.DragScrollProfile() { - @Override - public float getSpeed(float w, long t) { - if (w > 0.8f) { - // Traverse all views in a millisecond - return ((float) mAdapter.getCount()) / 0.001f; - } else { - return 10.0f * w; - } - } - }; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.warp_main); - - DragSortListView lv = (DragSortListView) getListView(); - - lv.setDropListener(mDropListener); - lv.setRemoveListener(mRemoveListener); - lv.setDragScrollProfile(mDragScrollProfile); - - String[] array = getResources().getStringArray(R.array.countries); - List list = new ArrayList(Arrays.asList(array)); - - mAdapter = new ArrayAdapter(this, R.layout.list_item_handle_right, R.id.text, list); - setListAdapter(mAdapter); - } - -} diff --git a/libraries/drag-sort-listview/gradlew b/libraries/drag-sort-listview/gradlew deleted file mode 100755 index 91a7e269..00000000 --- a/libraries/drag-sort-listview/gradlew +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/libraries/drag-sort-listview/gradlew.bat b/libraries/drag-sort-listview/gradlew.bat deleted file mode 100644 index 8a0b282a..00000000 --- a/libraries/drag-sort-listview/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/libraries/drag-sort-listview/library/.gitignore b/libraries/drag-sort-listview/library/.gitignore deleted file mode 100644 index a45024b5..00000000 --- a/libraries/drag-sort-listview/library/.gitignore +++ /dev/null @@ -1,22 +0,0 @@ -# built application files -*.apk -*.ap_ - -# files for the dex VM -*.dex - -# Java class files -*.class - -# generated files -bin/ -gen/ -target/ - -# Local configuration file (sdk path, etc) -local.properties -.gitattributes - -# Eclipse project files -.classpath -.project diff --git a/libraries/drag-sort-listview/library/AndroidManifest.xml b/libraries/drag-sort-listview/library/AndroidManifest.xml deleted file mode 100644 index 20e41b7d..00000000 --- a/libraries/drag-sort-listview/library/AndroidManifest.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - diff --git a/libraries/drag-sort-listview/library/build.gradle b/libraries/drag-sort-listview/library/build.gradle deleted file mode 100644 index 2207334c..00000000 --- a/libraries/drag-sort-listview/library/build.gradle +++ /dev/null @@ -1,34 +0,0 @@ -apply plugin: 'com.android.library' - -dependencies { - compile 'com.android.support:support-v4:21.+' -} - -android { - compileSdkVersion 21 - buildToolsVersion "21.1.1" - - sourceSets { - main { - manifest.srcFile 'AndroidManifest.xml' - java.srcDirs = ['src'] - resources.srcDirs = ['src'] - aidl.srcDirs = ['src'] - renderscript.srcDirs = ['src'] - res.srcDirs = ['res'] - assets.srcDirs = ['assets'] - } - - // Move the tests to tests/java, tests/res, etc... - instrumentTest.setRoot('tests') - - // Move the build types to build-types/ - // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... - // This moves them out of them default location under src//... which would - // conflict with src/ being used by the main source set. - // Adding new build types or product flavors should be accompanied - // by a similar customization. - debug.setRoot('build-types/debug') - release.setRoot('build-types/release') - } -} diff --git a/libraries/drag-sort-listview/library/pom.xml b/libraries/drag-sort-listview/library/pom.xml deleted file mode 100644 index bf41668f..00000000 --- a/libraries/drag-sort-listview/library/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - 4.0.0 - - com.mobeta.android.dslv - drag-sort-listview - apklib - 0.6.2-SNAPSHOT - - - com.mobeta.android.dslv - parent - 0.6.2-SNAPSHOT - ../pom.xml - - - - - com.google.android - android - provided - - - com.google.android - support-v4 - true - - - - - src - test - - - - com.jayway.maven.plugins.android.generation2 - android-maven-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.7 - - - com.google.doclava - doclava - 1.0.5 - - com.google.doclava.Doclava - - ${sun.boot.class.path} - - -quiet - -federate Android http://d.android.com/reference - -federationxml Android - http://doclava.googlecode.com/svn/static/api/android-10.xml - -hdf project.name "${project.name}" - -d ${project.build.directory}/apidocs - - false - - -J-Xmx1024m - - - - - diff --git a/libraries/drag-sort-listview/library/proguard-project.txt b/libraries/drag-sort-listview/library/proguard-project.txt deleted file mode 100644 index f2fe1559..00000000 --- a/libraries/drag-sort-listview/library/proguard-project.txt +++ /dev/null @@ -1,20 +0,0 @@ -# To enable ProGuard in your project, edit project.properties -# to define the proguard.config property as described in that file. -# -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in ${sdk.dir}/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/libraries/drag-sort-listview/library/project.properties b/libraries/drag-sort-listview/library/project.properties deleted file mode 100644 index 0824dc1d..00000000 --- a/libraries/drag-sort-listview/library/project.properties +++ /dev/null @@ -1,16 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system edit -# "ant.properties", and override values to adapt the script to your -# project structure. -# -# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): -#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt - -android.library=true - -# Project target. -target=android-19 diff --git a/libraries/drag-sort-listview/library/res/values/dslv_attrs.xml b/libraries/drag-sort-listview/library/res/values/dslv_attrs.xml deleted file mode 100644 index 538ef1f4..00000000 --- a/libraries/drag-sort-listview/library/res/values/dslv_attrs.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortController.java b/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortController.java deleted file mode 100644 index 29ed7de4..00000000 --- a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortController.java +++ /dev/null @@ -1,466 +0,0 @@ -package com.mobeta.android.dslv; - -import android.graphics.Point; -import android.view.GestureDetector; -import android.view.HapticFeedbackConstants; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewConfiguration; -import android.widget.AdapterView; - -/** - * Class that starts and stops item drags on a {@link DragSortListView} - * based on touch gestures. This class also inherits from - * {@link SimpleFloatViewManager}, which provides basic float View - * creation. - *

- * An instance of this class is meant to be passed to the methods - * {@link DragSortListView#setTouchListener()} and - * {@link DragSortListView#setFloatViewManager()} of your - * {@link DragSortListView} instance. - */ -public class DragSortController extends SimpleFloatViewManager implements View.OnTouchListener, - GestureDetector.OnGestureListener { - - /** - * Drag init mode enum. - */ - public static final int ON_DOWN = 0; - public static final int ON_DRAG = 1; - public static final int ON_LONG_PRESS = 2; - - private int mDragInitMode = ON_DOWN; - - private boolean mSortEnabled = true; - - /** - * Remove mode enum. - */ - public static final int CLICK_REMOVE = 0; - public static final int FLING_REMOVE = 1; - - /** - * The current remove mode. - */ - private int mRemoveMode; - - private boolean mRemoveEnabled = false; - private boolean mIsRemoving = false; - - private GestureDetector mDetector; - - private GestureDetector mFlingRemoveDetector; - - private int mTouchSlop; - - public static final int MISS = -1; - - private int mHitPos = MISS; - private int mFlingHitPos = MISS; - - private int mClickRemoveHitPos = MISS; - - private int[] mTempLoc = new int[2]; - - private int mItemX; - private int mItemY; - - private int mCurrX; - private int mCurrY; - - private boolean mDragging = false; - - private float mFlingSpeed = 500f; - - private int mDragHandleId; - - private int mClickRemoveId; - - private int mFlingHandleId; - private boolean mCanDrag; - - private DragSortListView mDslv; - private int mPositionX; - - /** - * Calls {@link #DragSortController(DragSortListView, int)} with a - * 0 drag handle id, FLING_RIGHT_REMOVE remove mode, - * and ON_DOWN drag init. By default, sorting is enabled, and - * removal is disabled. - * - * @param dslv The DSLV instance - */ - public DragSortController(DragSortListView dslv) { - this(dslv, 0, ON_DOWN, FLING_REMOVE); - } - - public DragSortController(DragSortListView dslv, int dragHandleId, int dragInitMode, - int removeMode) { - - this(dslv, dragHandleId, dragInitMode, removeMode, 0); - } - - public DragSortController(DragSortListView dslv, int dragHandleId, int dragInitMode, - int removeMode, int clickRemoveId) { - - this(dslv, dragHandleId, dragInitMode, removeMode, clickRemoveId, 0); - } - - /** - * By default, sorting is enabled, and removal is disabled. - * - * @param dslv The DSLV instance - * @param dragHandleId The resource id of the View that represents - * the drag handle in a list item. - */ - public DragSortController(DragSortListView dslv, int dragHandleId, int dragInitMode, - int removeMode, int clickRemoveId, int flingHandleId) { - - super(dslv); - mDslv = dslv; - mDetector = new GestureDetector(dslv.getContext(), this); - mFlingRemoveDetector = new GestureDetector(dslv.getContext(), mFlingRemoveListener); - mFlingRemoveDetector.setIsLongpressEnabled(false); - mTouchSlop = ViewConfiguration.get(dslv.getContext()).getScaledTouchSlop(); - mDragHandleId = dragHandleId; - mClickRemoveId = clickRemoveId; - mFlingHandleId = flingHandleId; - setRemoveMode(removeMode); - setDragInitMode(dragInitMode); - } - - - public int getDragInitMode() { - return mDragInitMode; - } - - /** - * Set how a drag is initiated. Needs to be one of - * {@link ON_DOWN}, {@link ON_DRAG}, or {@link ON_LONG_PRESS}. - * - * @param mode The drag init mode. - */ - public void setDragInitMode(int mode) { - mDragInitMode = mode; - } - - /** - * Enable/Disable list item sorting. Disabling is useful if only item - * removal is desired. Prevents drags in the vertical direction. - * - * @param enabled Set true to enable list - * item sorting. - */ - public void setSortEnabled(boolean enabled) { - mSortEnabled = enabled; - } - - public boolean isSortEnabled() { - return mSortEnabled; - } - - /** - * One of {@link CLICK_REMOVE}, {@link FLING_RIGHT_REMOVE}, - * {@link FLING_LEFT_REMOVE}, - * {@link SLIDE_RIGHT_REMOVE}, or {@link SLIDE_LEFT_REMOVE}. - */ - public void setRemoveMode(int mode) { - mRemoveMode = mode; - } - - public int getRemoveMode() { - return mRemoveMode; - } - - /** - * Enable/Disable item removal without affecting remove mode. - */ - public void setRemoveEnabled(boolean enabled) { - mRemoveEnabled = enabled; - } - - public boolean isRemoveEnabled() { - return mRemoveEnabled; - } - - /** - * Set the resource id for the View that represents the drag - * handle in a list item. - * - * @param id An android resource id. - */ - public void setDragHandleId(int id) { - mDragHandleId = id; - } - - /** - * Set the resource id for the View that represents the fling - * handle in a list item. - * - * @param id An android resource id. - */ - public void setFlingHandleId(int id) { - mFlingHandleId = id; - } - - /** - * Set the resource id for the View that represents click - * removal button. - * - * @param id An android resource id. - */ - public void setClickRemoveId(int id) { - mClickRemoveId = id; - } - - /** - * Sets flags to restrict certain motions of the floating View - * based on DragSortController settings (such as remove mode). - * Starts the drag on the DragSortListView. - * - * @param position The list item position (includes headers). - * @param deltaX Touch x-coord minus left edge of floating View. - * @param deltaY Touch y-coord minus top edge of floating View. - * @return True if drag started, false otherwise. - */ - public boolean startDrag(int position, int deltaX, int deltaY) { - - int dragFlags = 0; - if (mSortEnabled && !mIsRemoving) { - dragFlags |= DragSortListView.DRAG_POS_Y | DragSortListView.DRAG_NEG_Y; - } - if (mRemoveEnabled && mIsRemoving) { - dragFlags |= DragSortListView.DRAG_POS_X; - dragFlags |= DragSortListView.DRAG_NEG_X; - } - - mDragging = mDslv.startDrag(position - mDslv.getHeaderViewsCount(), dragFlags, deltaX, - deltaY); - return mDragging; - } - - @Override - public boolean onTouch(View v, MotionEvent ev) { - if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) { - return false; - } - - mDetector.onTouchEvent(ev); - if (mRemoveEnabled && mDragging && mRemoveMode == FLING_REMOVE) { - mFlingRemoveDetector.onTouchEvent(ev); - } - - int action = ev.getAction() & MotionEvent.ACTION_MASK; - switch (action) { - case MotionEvent.ACTION_DOWN: - mCurrX = (int) ev.getX(); - mCurrY = (int) ev.getY(); - break; - case MotionEvent.ACTION_UP: - if (mRemoveEnabled && mIsRemoving) { - int x = mPositionX >= 0 ? mPositionX : -mPositionX; - int removePoint = mDslv.getWidth() / 2; - if (x > removePoint) { - mDslv.stopDragWithVelocity(true, 0); - } - } - case MotionEvent.ACTION_CANCEL: - mIsRemoving = false; - mDragging = false; - break; - } - - return false; - } - - /** - * Overrides to provide fading when slide removal is enabled. - */ - @Override - public void onDragFloatView(View floatView, Point position, Point touch) { - - if (mRemoveEnabled && mIsRemoving) { - mPositionX = position.x; - } - } - - /** - * Get the position to start dragging based on the ACTION_DOWN - * MotionEvent. This function simply calls - * {@link #dragHandleHitPosition(MotionEvent)}. Override - * to change drag handle behavior; - * this function is called internally when an ACTION_DOWN - * event is detected. - * - * @param ev The ACTION_DOWN MotionEvent. - * @return The list position to drag if a drag-init gesture is - * detected; MISS if unsuccessful. - */ - public int startDragPosition(MotionEvent ev) { - return dragHandleHitPosition(ev); - } - - public int startFlingPosition(MotionEvent ev) { - return mRemoveMode == FLING_REMOVE ? flingHandleHitPosition(ev) : MISS; - } - - /** - * Checks for the touch of an item's drag handle (specified by - * {@link #setDragHandleId(int)}), and returns that item's position - * if a drag handle touch was detected. - * - * @param ev The ACTION_DOWN MotionEvent. - * @return The list position of the item whose drag handle was - * touched; MISS if unsuccessful. - */ - public int dragHandleHitPosition(MotionEvent ev) { - return viewIdHitPosition(ev, mDragHandleId); - } - - public int flingHandleHitPosition(MotionEvent ev) { - return viewIdHitPosition(ev, mFlingHandleId); - } - - public int viewIdHitPosition(MotionEvent ev, int id) { - final int x = (int) ev.getX(); - final int y = (int) ev.getY(); - - int touchPos = mDslv.pointToPosition(x, y); // includes headers/footers - - final int numHeaders = mDslv.getHeaderViewsCount(); - final int numFooters = mDslv.getFooterViewsCount(); - final int count = mDslv.getCount(); - - // We're only interested if the touch was on an - // item that's not a header or footer. - if (touchPos != AdapterView.INVALID_POSITION && touchPos >= numHeaders - && touchPos < (count - numFooters)) { - final View item = mDslv.getChildAt(touchPos - mDslv.getFirstVisiblePosition()); - final int rawX = (int) ev.getRawX(); - final int rawY = (int) ev.getRawY(); - - View dragBox = id == 0 ? item : (View) item.findViewById(id); - if (dragBox != null) { - dragBox.getLocationOnScreen(mTempLoc); - - if (rawX > mTempLoc[0] && rawY > mTempLoc[1] && - rawX < mTempLoc[0] + dragBox.getWidth() && - rawY < mTempLoc[1] + dragBox.getHeight()) { - - mItemX = item.getLeft(); - mItemY = item.getTop(); - - return touchPos; - } - } - } - - return MISS; - } - - @Override - public boolean onDown(MotionEvent ev) { - if (mRemoveEnabled && mRemoveMode == CLICK_REMOVE) { - mClickRemoveHitPos = viewIdHitPosition(ev, mClickRemoveId); - } - - mHitPos = startDragPosition(ev); - if (mHitPos != MISS && mDragInitMode == ON_DOWN) { - startDrag(mHitPos, (int) ev.getX() - mItemX, (int) ev.getY() - mItemY); - } - - mIsRemoving = false; - mCanDrag = true; - mPositionX = 0; - mFlingHitPos = startFlingPosition(ev); - - return true; - } - - @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - - final int x1 = (int) e1.getX(); - final int y1 = (int) e1.getY(); - final int x2 = (int) e2.getX(); - final int y2 = (int) e2.getY(); - final int deltaX = x2 - mItemX; - final int deltaY = y2 - mItemY; - - if (mCanDrag && !mDragging && (mHitPos != MISS || mFlingHitPos != MISS)) { - if (mHitPos != MISS) { - if (mDragInitMode == ON_DRAG && Math.abs(y2 - y1) > mTouchSlop && mSortEnabled) { - startDrag(mHitPos, deltaX, deltaY); - } else if (mDragInitMode != ON_DOWN && Math.abs(x2 - x1) > mTouchSlop - && mRemoveEnabled) { - mIsRemoving = true; - startDrag(mFlingHitPos, deltaX, deltaY); - } - } else if (mFlingHitPos != MISS) { - if (Math.abs(x2 - x1) > mTouchSlop && mRemoveEnabled) { - mIsRemoving = true; - startDrag(mFlingHitPos, deltaX, deltaY); - } else if (Math.abs(y2 - y1) > mTouchSlop) { - mCanDrag = false; // if started to scroll the list then - // don't allow sorting nor fling-removing - } - } - } - return false; - } - - @Override - public void onLongPress(MotionEvent e) { - if (mHitPos != MISS && mDragInitMode == ON_LONG_PRESS) { - mDslv.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); - startDrag(mHitPos, mCurrX - mItemX, mCurrY - mItemY); - } - } - - // complete the OnGestureListener interface - @Override - public final boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - return false; - } - - // complete the OnGestureListener interface - @Override - public boolean onSingleTapUp(MotionEvent ev) { - if (mRemoveEnabled && mRemoveMode == CLICK_REMOVE) { - if (mClickRemoveHitPos != MISS) { - mDslv.removeItem(mClickRemoveHitPos - mDslv.getHeaderViewsCount()); - } - } - return true; - } - - // complete the OnGestureListener interface - @Override - public void onShowPress(MotionEvent ev) { - // do nothing - } - - private GestureDetector.OnGestureListener mFlingRemoveListener = - new GestureDetector.SimpleOnGestureListener() { - @Override - public final boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, - float velocityY) { - if (mRemoveEnabled && mIsRemoving) { - int w = mDslv.getWidth(); - int minPos = w / 5; - if (velocityX > mFlingSpeed) { - if (mPositionX > -minPos) { - mDslv.stopDragWithVelocity(true, velocityX); - } - } else if (velocityX < -mFlingSpeed) { - if (mPositionX < minPos) { - mDslv.stopDragWithVelocity(true, velocityX); - } - } - mIsRemoving = false; - } - return false; - } - }; - -} diff --git a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortCursorAdapter.java b/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortCursorAdapter.java deleted file mode 100644 index 5b66e59e..00000000 --- a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortCursorAdapter.java +++ /dev/null @@ -1,232 +0,0 @@ -package com.mobeta.android.dslv; - -import android.content.Context; -import android.database.Cursor; -import android.support.v4.widget.CursorAdapter; -import android.util.SparseIntArray; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ListAdapter; - -import java.util.ArrayList; -import java.util.List; - - -/** - * A subclass of {@link android.widget.CursorAdapter} that provides - * reordering of the elements in the Cursor based on completed - * drag-sort operations. The reordering is a simple mapping of - * list positions into Cursor positions (the Cursor is unchanged). - * To persist changes made by drag-sorts, one can retrieve the - * mapping with the {@link #getCursorPositions()} method, which - * returns the reordered list of Cursor positions. - *

- * An instance of this class is passed - * to {@link DragSortListView#setAdapter(ListAdapter)} and, since - * this class implements the {@link DragSortListView.DragSortListener} - * interface, it is automatically set as the DragSortListener for - * the DragSortListView instance. - */ -public abstract class DragSortCursorAdapter extends CursorAdapter implements - DragSortListView.DragSortListener { - - private static final int REMOVED = -1; - - /** - * Key is ListView position, value is Cursor position - */ - private SparseIntArray mListMapping = new SparseIntArray(); - - private List mRemovedCursorPositions = new ArrayList(); - - @Deprecated - public DragSortCursorAdapter(Context context, Cursor c) { - super(context, c); - } - - public DragSortCursorAdapter(Context context, Cursor c, boolean autoRequery) { - super(context, c, autoRequery); - } - - public DragSortCursorAdapter(Context context, Cursor c, int flags) { - super(context, c, flags); - } - - /** - * Swaps Cursor and clears list-Cursor mapping. - * - * @see android.widget.CursorAdapter#swapCursor(android.database.Cursor) - */ - @Override - public Cursor swapCursor(Cursor newCursor) { - Cursor old = super.swapCursor(newCursor); - resetMappings(); - return old; - } - - /** - * Resets list-cursor mapping. - */ - public void reset() { - resetMappings(); - notifyDataSetChanged(); - } - - private void resetMappings() { - mListMapping.clear(); - mRemovedCursorPositions.clear(); - } - - @Override - public Object getItem(int position) { - return super.getItem(mListMapping.get(position, position)); - } - - @Override - public long getItemId(int position) { - return super.getItemId(mListMapping.get(position, position)); - } - - @Override - public View getDropDownView(int position, View convertView, ViewGroup parent) { - return super.getDropDownView(mListMapping.get(position, position), convertView, parent); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - return super.getView(mListMapping.get(position, position), convertView, parent); - } - - /** - * On drop, this updates the mapping between Cursor positions - * and ListView positions. The Cursor is unchanged. Retrieve - * the current mapping with {@link getCursorPositions()}. - * - * @see DragSortListView.DropListener#drop(int, int) - */ - @Override - public void drop(int from, int to) { - if (from != to) { - int cursorFrom = mListMapping.get(from, from); - - if (from > to) { - for (int i = from; i > to; i--) { - mListMapping.put(i, mListMapping.get(i - 1, i - 1)); - } - } else { - for (int i = from; i < to; i++) { - mListMapping.put(i, mListMapping.get(i + 1, i + 1)); - } - } - mListMapping.put(to, cursorFrom); - - cleanMapping(); - notifyDataSetChanged(); - } - } - - /** - * On remove, this updates the mapping between Cursor positions - * and ListView positions. The Cursor is unchanged. Retrieve - * the current mapping with {@link getCursorPositions()}. - * - * @see DragSortListView.RemoveListener#remove(int) - */ - @Override - public void remove(int which) { - int cursorPos = mListMapping.get(which, which); - if (!mRemovedCursorPositions.contains(cursorPos)) { - mRemovedCursorPositions.add(cursorPos); - } - - int newCount = getCount(); - for (int i = which; i < newCount; i++) { - mListMapping.put(i, mListMapping.get(i + 1, i + 1)); - } - - mListMapping.delete(newCount); - - cleanMapping(); - notifyDataSetChanged(); - } - - /** - * Does nothing. Just completes DragSortListener interface. - */ - @Override - public void drag(int from, int to) { - // do nothing - } - - /** - * Remove unnecessary mappings from sparse array. - */ - private void cleanMapping() { - List toRemove = new ArrayList(); - - final int size = mListMapping.size(); - for (int i = 0; i < size; i++) { - if (mListMapping.keyAt(i) == mListMapping.valueAt(i)) { - toRemove.add(mListMapping.keyAt(i)); - } - } - - for (int position : toRemove) { - mListMapping.delete(position); - } - } - - @Override - public int getCount() { - return super.getCount() - mRemovedCursorPositions.size(); - } - - /** - * Get the Cursor position mapped to by the provided list position - * (given all previously handled drag-sort - * operations). - * - * @param position List position - * @return The mapped-to Cursor position - */ - public int getCursorPosition(int position) { - return mListMapping.get(position, position); - } - - /** - * Get the current order of Cursor positions presented by the - * list. - */ - public List getCursorPositions() { - List result = new ArrayList(); - - for (int i = 0; i < getCount(); i++) { - result.add(mListMapping.get(i, i)); - } - - return result; - } - - /** - * Get the list position mapped to by the provided Cursor position. - * If the provided Cursor position has been removed by a drag-sort, - * this returns {@link #REMOVED}. - * - * @param cursorPosition A Cursor position - * @return The mapped-to list position or REMOVED - */ - public int getListPosition(int cursorPosition) { - if (mRemovedCursorPositions.contains(cursorPosition)) { - return REMOVED; - } - - int index = mListMapping.indexOfValue(cursorPosition); - if (index < 0) { - return cursorPosition; - } else { - return mListMapping.keyAt(index); - } - } - - -} diff --git a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortItemView.java b/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortItemView.java deleted file mode 100644 index 66dbe7f6..00000000 --- a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortItemView.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.mobeta.android.dslv; - -import android.content.Context; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AbsListView; - -/** - * Lightweight ViewGroup that wraps list items obtained from user's - * ListAdapter. ItemView expects a single child that has a definite - * height (i.e. the child's layout height is not MATCH_PARENT). - * The width of - * ItemView will always match the width of its child (that is, - * the width MeasureSpec given to ItemView is passed directly - * to the child, and the ItemView measured width is set to the - * child's measured width). The height of ItemView can be anything; - * the - *

- *

- * The purpose of this class is to optimize slide - * shuffle animations. - */ -public class DragSortItemView extends ViewGroup { - - private int mGravity = Gravity.TOP; - - public DragSortItemView(Context context) { - super(context); - - // always init with standard ListView layout params - setLayoutParams(new AbsListView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); - - //setClipChildren(true); - } - - public void setGravity(int gravity) { - mGravity = gravity; - } - - public int getGravity() { - return mGravity; - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - final View child = getChildAt(0); - - if (child == null) { - return; - } - - if (mGravity == Gravity.TOP) { - child.layout(0, 0, getMeasuredWidth(), child.getMeasuredHeight()); - } else { - child.layout(0, getMeasuredHeight() - child.getMeasuredHeight(), - getMeasuredWidth(), getMeasuredHeight()); - } - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int height = MeasureSpec.getSize(heightMeasureSpec); - int width = MeasureSpec.getSize(widthMeasureSpec); - - int heightMode = MeasureSpec.getMode(heightMeasureSpec); - - final View child = getChildAt(0); - if (child == null) { - setMeasuredDimension(0, width); - return; - } - - if (child.isLayoutRequested()) { - // Always let child be as tall as it wants. - measureChild(child, widthMeasureSpec, - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); - } - - if (heightMode == MeasureSpec.UNSPECIFIED) { - ViewGroup.LayoutParams lp = getLayoutParams(); - - if (lp.height > 0) { - height = lp.height; - } else { - height = child.getMeasuredHeight(); - } - } - - setMeasuredDimension(width, height); - } - -} diff --git a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortItemViewCheckable.java b/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortItemViewCheckable.java deleted file mode 100644 index a165b9dd..00000000 --- a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortItemViewCheckable.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.mobeta.android.dslv; - -import android.content.Context; -import android.view.View; -import android.widget.Checkable; - -/** - * Lightweight ViewGroup that wraps list items obtained from user's - * ListAdapter. ItemView expects a single child that has a definite - * height (i.e. the child's layout height is not MATCH_PARENT). - * The width of - * ItemView will always match the width of its child (that is, - * the width MeasureSpec given to ItemView is passed directly - * to the child, and the ItemView measured width is set to the - * child's measured width). The height of ItemView can be anything; - * the - *

- *

- * The purpose of this class is to optimize slide - * shuffle animations. - */ -public class DragSortItemViewCheckable extends DragSortItemView implements Checkable { - - public DragSortItemViewCheckable(Context context) { - super(context); - } - - @Override - public boolean isChecked() { - View child = getChildAt(0); - if (child instanceof Checkable) { - return ((Checkable) child).isChecked(); - } else { - return false; - } - } - - @Override - public void setChecked(boolean checked) { - View child = getChildAt(0); - if (child instanceof Checkable) { - ((Checkable) child).setChecked(checked); - } - } - - @Override - public void toggle() { - View child = getChildAt(0); - if (child instanceof Checkable) { - ((Checkable) child).toggle(); - } - } -} diff --git a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortListView.java b/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortListView.java deleted file mode 100644 index c987340d..00000000 --- a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/DragSortListView.java +++ /dev/null @@ -1,2983 +0,0 @@ -/* - * DragSortListView. - * - * A subclass of the Android ListView component that enables drag - * and drop re-ordering of list items. - * - * Copyright 2012 Carl Bauer - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mobeta.android.dslv; - -import android.content.Context; -import android.content.res.TypedArray; -import android.database.DataSetObserver; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Point; -import android.graphics.drawable.Drawable; -import android.os.Environment; -import android.os.SystemClock; -import android.util.AttributeSet; -import android.util.Log; -import android.util.SparseBooleanArray; -import android.util.SparseIntArray; -import android.view.Gravity; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AbsListView; -import android.widget.BaseAdapter; -import android.widget.Checkable; -import android.widget.ListAdapter; -import android.widget.ListView; -import android.widget.WrapperListAdapter; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - * ListView subclass that mediates drag and drop resorting of items. - * - * @author heycosmo - */ -public class DragSortListView extends ListView { - - - /** - * The View that floats above the ListView and represents - * the dragged item. - */ - private View mFloatView; - - /** - * The float View location. First based on touch location - * and given deltaX and deltaY. Then restricted by callback - * to FloatViewManager.onDragFloatView(). Finally restricted - * by bounds of DSLV. - */ - private Point mFloatLoc = new Point(); - - private Point mTouchLoc = new Point(); - - /** - * The middle (in the y-direction) of the floating View. - */ - private int mFloatViewMid; - - /** - * Flag to make sure float View isn't measured twice - */ - private boolean mFloatViewOnMeasured = false; - - /** - * Watch the Adapter for data changes. Cancel a drag if - * coincident with a change. - */ - private DataSetObserver mObserver; - - /** - * Transparency for the floating View (XML attribute). - */ - private float mFloatAlpha = 1.0f; - private float mCurrFloatAlpha = 1.0f; - - /** - * While drag-sorting, the current position of the floating - * View. If dropped, the dragged item will land in this position. - */ - private int mFloatPos; - - /** - * The first expanded ListView position that helps represent - * the drop slot tracking the floating View. - */ - private int mFirstExpPos; - - /** - * The second expanded ListView position that helps represent - * the drop slot tracking the floating View. This can equal - * mFirstExpPos if there is no slide shuffle occurring; otherwise - * it is equal to mFirstExpPos + 1. - */ - private int mSecondExpPos; - - /** - * Flag set if slide shuffling is enabled. - */ - private boolean mAnimate = false; - - /** - * The user dragged from this position. - */ - private int mSrcPos; - - /** - * Offset (in x) within the dragged item at which the user - * picked it up (or first touched down with the digitalis). - */ - private int mDragDeltaX; - - /** - * Offset (in y) within the dragged item at which the user - * picked it up (or first touched down with the digitalis). - */ - private int mDragDeltaY; - - - /** - * The difference (in x) between screen coordinates and coordinates - * in this view. - */ - //private int mOffsetX; - - /** - * The difference (in y) between screen coordinates and coordinates - * in this view. - */ - //private int mOffsetY; - - /** - * A listener that receives callbacks whenever the floating View - * hovers over a new position. - */ - private DragListener mDragListener; - - /** - * A listener that receives a callback when the floating View - * is dropped. - */ - private DropListener mDropListener; - - /** - * A listener that receives a callback when the floating View - * (or more precisely the originally dragged item) is removed - * by one of the provided gestures. - */ - private RemoveListener mRemoveListener; - - /** - * Enable/Disable item dragging - * - * @attr name dslv:drag_enabled - */ - private boolean mDragEnabled = true; - - /** - * Drag state enum. - */ - private final static int IDLE = 0; - private final static int REMOVING = 1; - private final static int DROPPING = 2; - private final static int STOPPED = 3; - private final static int DRAGGING = 4; - - private int mDragState = IDLE; - - /** - * Height in pixels to which the originally dragged item - * is collapsed during a drag-sort. Currently, this value - * must be greater than zero. - */ - private int mItemHeightCollapsed = 1; - - /** - * Height of the floating View. Stored for the purpose of - * providing the tracking drop slot. - */ - private int mFloatViewHeight; - - /** - * Convenience member. See above. - */ - private int mFloatViewHeightHalf; - - /** - * Save the given width spec for use in measuring children - */ - private int mWidthMeasureSpec = 0; - - /** - * Sample Views ultimately used for calculating the height - * of ListView items that are off-screen. - */ - private View[] mSampleViewTypes = new View[1]; - - /** - * Drag-scroll encapsulator! - */ - private DragScroller mDragScroller; - - /** - * Determines the start of the upward drag-scroll region - * at the top of the ListView. Specified by a fraction - * of the ListView height, thus screen resolution agnostic. - */ - private float mDragUpScrollStartFrac = 1.0f / 3.0f; - - /** - * Determines the start of the downward drag-scroll region - * at the bottom of the ListView. Specified by a fraction - * of the ListView height, thus screen resolution agnostic. - */ - private float mDragDownScrollStartFrac = 1.0f / 3.0f; - - /** - * The following are calculated from the above fracs. - */ - private int mUpScrollStartY; - private int mDownScrollStartY; - private float mDownScrollStartYF; - private float mUpScrollStartYF; - - /** - * Calculated from above above and current ListView height. - */ - private float mDragUpScrollHeight; - - /** - * Calculated from above above and current ListView height. - */ - private float mDragDownScrollHeight; - - /** - * Maximum drag-scroll speed in pixels per ms. Only used with - * default linear drag-scroll profile. - */ - private float mMaxScrollSpeed = 0.5f; - - /** - * Defines the scroll speed during a drag-scroll. User can - * provide their own; this default is a simple linear profile - * where scroll speed increases linearly as the floating View - * nears the top/bottom of the ListView. - */ - private DragScrollProfile mScrollProfile = new DragScrollProfile() { - @Override - public float getSpeed(float w, long t) { - return mMaxScrollSpeed * w; - } - }; - - /** - * Current touch x. - */ - private int mX; - - /** - * Current touch y. - */ - private int mY; - - /** - * Last touch x. - */ - //private int mLastX; - - /** - * Last touch y. - */ - private int mLastY; - - /** - * The touch y-coord at which drag started - */ - //private int mDragStartY; - - /** - * Drag flag bit. Floating View can move in the positive - * x direction. - */ - public final static int DRAG_POS_X = 0x1; - - /** - * Drag flag bit. Floating View can move in the negative - * x direction. - */ - public final static int DRAG_NEG_X = 0x2; - - /** - * Drag flag bit. Floating View can move in the positive - * y direction. This is subtle. What this actually means is - * that, if enabled, the floating View can be dragged below its starting - * position. Remove in favor of upper-bounding item position? - */ - public final static int DRAG_POS_Y = 0x4; - - /** - * Drag flag bit. Floating View can move in the negative - * y direction. This is subtle. What this actually means is - * that the floating View can be dragged above its starting - * position. Remove in favor of lower-bounding item position? - */ - public final static int DRAG_NEG_Y = 0x8; - - /** - * Flags that determine limits on the motion of the - * floating View. See flags above. - */ - private int mDragFlags = 0; - - /** - * Last call to an on*TouchEvent was a call to - * onInterceptTouchEvent. - */ - private boolean mLastCallWasIntercept = false; - - /** - * A touch event is in progress. - */ - private boolean mInTouchEvent = false; - - /** - * Let the user customize the floating View. - */ - private FloatViewManager mFloatViewManager = null; - - /** - * Given to ListView to cancel its action when a drag-sort - * begins. - */ - private MotionEvent mCancelEvent; - - /** - * Enum telling where to cancel the ListView action when a - * drag-sort begins - */ - private static final int NO_CANCEL = 0; - private static final int ON_TOUCH_EVENT = 1; - private static final int ON_INTERCEPT_TOUCH_EVENT = 2; - - /** - * Where to cancel the ListView action when a - * drag-sort begins - */ - private int mCancelMethod = NO_CANCEL; - - /** - * Determines when a slide shuffle animation starts. That is, - * defines how close to the edge of the drop slot the floating - * View must be to initiate the slide. - */ - private float mSlideRegionFrac = 0.25f; - - /** - * Number between 0 and 1 indicating the relative location of - * a sliding item (only used if drag-sort animations - * are turned on). Nearly 1 means the item is - * at the top of the slide region (nearly full blank item - * is directly below). - */ - private float mSlideFrac = 0.0f; - - /** - * Wraps the user-provided ListAdapter. This is used to wrap each - * item View given by the user inside another View (currenly - * a RelativeLayout) which - * expands and collapses to simulate the item shuffling. - */ - private AdapterWrapper mAdapterWrapper; - - /** - * Turn on custom debugger. - */ - private boolean mTrackDragSort = false; - - /** - * Debugging class. - */ - private DragSortTracker mDragSortTracker; - - /** - * Needed for adjusting item heights from within layoutChildren - */ - private boolean mBlockLayoutRequests = false; - - /** - * Set to true when a down event happens during drag sort; - * for example, when drag finish animations are - * playing. - */ - private boolean mIgnoreTouchEvent = false; - - /** - * Caches DragSortItemView child heights. Sometimes DSLV has to - * know the height of an offscreen item. Since ListView virtualizes - * these, DSLV must get the item from the ListAdapter to obtain - * its height. That process can be expensive, but often the same - * offscreen item will be requested many times in a row. Once an - * offscreen item height is calculated, we cache it in this guy. - * Actually, we cache the height of the child of the - * DragSortItemView since the item height changes often during a - * drag-sort. - */ - private static final int sCacheSize = 3; - private HeightCache mChildHeightCache = new HeightCache(sCacheSize); - - private RemoveAnimator mRemoveAnimator; - - private LiftAnimator mLiftAnimator; - - private DropAnimator mDropAnimator; - - private boolean mUseRemoveVelocity; - private float mRemoveVelocityX = 0; - - public DragSortListView(Context context, AttributeSet attrs) { - super(context, attrs); - - int defaultDuration = 150; - int removeAnimDuration = defaultDuration; // ms - int dropAnimDuration = defaultDuration; // ms - - if (attrs != null) { - TypedArray a = getContext().obtainStyledAttributes(attrs, - R.styleable.DragSortListView, 0, 0); - - mItemHeightCollapsed = Math.max(1, a.getDimensionPixelSize( - R.styleable.DragSortListView_collapsed_height, 1)); - - mTrackDragSort = a.getBoolean( - R.styleable.DragSortListView_track_drag_sort, false); - - if (mTrackDragSort) { - mDragSortTracker = new DragSortTracker(); - } - - // alpha between 0 and 255, 0=transparent, 255=opaque - mFloatAlpha = a.getFloat(R.styleable.DragSortListView_float_alpha, mFloatAlpha); - mCurrFloatAlpha = mFloatAlpha; - - mDragEnabled = a.getBoolean(R.styleable.DragSortListView_drag_enabled, mDragEnabled); - - mSlideRegionFrac = Math.max(0.0f, - Math.min(1.0f, 1.0f - a.getFloat( - R.styleable.DragSortListView_slide_shuffle_speed, - 0.75f))); - - mAnimate = mSlideRegionFrac > 0.0f; - - float frac = a.getFloat( - R.styleable.DragSortListView_drag_scroll_start, - mDragUpScrollStartFrac); - - setDragScrollStart(frac); - - mMaxScrollSpeed = a.getFloat( - R.styleable.DragSortListView_max_drag_scroll_speed, - mMaxScrollSpeed); - - removeAnimDuration = a.getInt( - R.styleable.DragSortListView_remove_animation_duration, - removeAnimDuration); - - dropAnimDuration = a.getInt( - R.styleable.DragSortListView_drop_animation_duration, - dropAnimDuration); - - boolean useDefault = a.getBoolean( - R.styleable.DragSortListView_use_default_controller, - true); - - if (useDefault) { - boolean removeEnabled = a.getBoolean( - R.styleable.DragSortListView_remove_enabled, - false); - int removeMode = a.getInt( - R.styleable.DragSortListView_remove_mode, - DragSortController.FLING_REMOVE); - boolean sortEnabled = a.getBoolean( - R.styleable.DragSortListView_sort_enabled, - true); - int dragInitMode = a.getInt( - R.styleable.DragSortListView_drag_start_mode, - DragSortController.ON_DOWN); - int dragHandleId = a.getResourceId( - R.styleable.DragSortListView_drag_handle_id, - 0); - int flingHandleId = a.getResourceId( - R.styleable.DragSortListView_fling_handle_id, - 0); - int clickRemoveId = a.getResourceId( - R.styleable.DragSortListView_click_remove_id, - 0); - int bgColor = a.getColor( - R.styleable.DragSortListView_float_background_color, - Color.BLACK); - - DragSortController controller = new DragSortController( - this, dragHandleId, dragInitMode, removeMode, - clickRemoveId, flingHandleId); - controller.setRemoveEnabled(removeEnabled); - controller.setSortEnabled(sortEnabled); - controller.setBackgroundColor(bgColor); - - mFloatViewManager = controller; - setOnTouchListener(controller); - } - - a.recycle(); - } - - mDragScroller = new DragScroller(); - - float smoothness = 0.5f; - if (removeAnimDuration > 0) { - mRemoveAnimator = new RemoveAnimator(smoothness, removeAnimDuration); - } - // mLiftAnimator = new LiftAnimator(smoothness, 100); - if (dropAnimDuration > 0) { - mDropAnimator = new DropAnimator(smoothness, dropAnimDuration); - } - - mCancelEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0f, 0f, 0f, 0f, 0, 0f, - 0f, 0, 0); - - // construct the dataset observer - mObserver = new DataSetObserver() { - private void cancel() { - if (mDragState == DRAGGING) { - cancelDrag(); - } - } - - @Override - public void onChanged() { - cancel(); - } - - @Override - public void onInvalidated() { - cancel(); - } - }; - } - - /** - * Usually called from a FloatViewManager. The float alpha - * will be reset to the xml-defined value every time a drag - * is stopped. - */ - public void setFloatAlpha(float alpha) { - mCurrFloatAlpha = alpha; - } - - public float getFloatAlpha() { - return mCurrFloatAlpha; - } - - /** - * Set maximum drag scroll speed in positions/second. Only applies - * if using default ScrollSpeedProfile. - * - * @param max Maximum scroll speed. - */ - public void setMaxScrollSpeed(float max) { - mMaxScrollSpeed = max; - } - - /** - * For each DragSortListView Listener interface implemented by - * adapter, this method calls the appropriate - * set*Listener method with adapter as the argument. - * - * @param adapter The ListAdapter providing data to back - * DragSortListView. - * @see android.widget.ListView#setAdapter(android.widget.ListAdapter) - */ - @Override - public void setAdapter(ListAdapter adapter) { - if (adapter != null) { - mAdapterWrapper = new AdapterWrapper(adapter); - adapter.registerDataSetObserver(mObserver); - - if (adapter instanceof DropListener) { - setDropListener((DropListener) adapter); - } - if (adapter instanceof DragListener) { - setDragListener((DragListener) adapter); - } - if (adapter instanceof RemoveListener) { - setRemoveListener((RemoveListener) adapter); - } - } else { - mAdapterWrapper = null; - } - - super.setAdapter(mAdapterWrapper); - } - - /** - * As opposed to {@link ListView#getAdapter()}, which returns - * a heavily wrapped ListAdapter (DragSortListView wraps the - * input ListAdapter {\emph and} ListView wraps the wrapped one). - * - * @return The ListAdapter set as the argument of {@link setAdapter()} - */ - public ListAdapter getInputAdapter() { - if (mAdapterWrapper == null) { - return null; - } else { - return mAdapterWrapper.getWrappedAdapter(); - } - } - - private class AdapterWrapper extends BaseAdapter implements WrapperListAdapter { - private ListAdapter mAdapter; - - public AdapterWrapper(ListAdapter adapter) { - mAdapter = adapter; - } - - @Override - public ListAdapter getWrappedAdapter() { - return mAdapter; - } - - @Override - public long getItemId(int position) { - return mAdapter.getItemId(position); - } - - @Override - public Object getItem(int position) { - return mAdapter.getItem(position); - } - - @Override - public int getCount() { - return mAdapter.getCount(); - } - - @Override - public boolean areAllItemsEnabled() { - return mAdapter.areAllItemsEnabled(); - } - - @Override - public boolean isEnabled(int position) { - return mAdapter.isEnabled(position); - } - - @Override - public int getItemViewType(int position) { - return mAdapter.getItemViewType(position); - } - - @Override - public int getViewTypeCount() { - return mAdapter.getViewTypeCount(); - } - - @Override - public boolean hasStableIds() { - return mAdapter.hasStableIds(); - } - - @Override - public boolean isEmpty() { - return mAdapter.isEmpty(); - } - - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - DragSortItemView v; - View child; - if (convertView != null) { - v = (DragSortItemView) convertView; - View oldChild = v.getChildAt(0); - - child = mAdapter.getView(position, oldChild, DragSortListView.this); - if (child != oldChild) { - // shouldn't get here if user is reusing convertViews - // properly - if (oldChild != null) { - v.removeViewAt(0); - } - v.addView(child); - } - } else { - child = mAdapter.getView(position, null, DragSortListView.this); - if (child instanceof Checkable) { - v = new DragSortItemViewCheckable(getContext()); - } else { - v = new DragSortItemView(getContext()); - } - v.setLayoutParams(new AbsListView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); - v.addView(child); - } - - // Set the correct item height given drag state; passed - // View needs to be measured if measurement is required. - adjustItem(position + getHeaderViewsCount(), v, true); - - return v; - } - - @Override - public void registerDataSetObserver(DataSetObserver observer) { - mAdapter.registerDataSetObserver(observer); - } - - @Override - public void unregisterDataSetObserver(DataSetObserver observer) { - mAdapter.unregisterDataSetObserver(observer); - } - } - - private void drawDivider(int expPosition, Canvas canvas) { - final Drawable divider = getDivider(); - final int dividerHeight = getDividerHeight(); - - if (divider != null && dividerHeight != 0) { - final ViewGroup expItem = (ViewGroup) getChildAt(expPosition - - getFirstVisiblePosition()); - if (expItem != null) { - final int left = getPaddingLeft(); - final int right = getWidth() - getPaddingRight(); - final int top; - final int bottom; - - final int childHeight = expItem.getChildAt(0).getHeight(); - - if (expPosition > mSrcPos) { - top = expItem.getTop() + childHeight; - bottom = top + dividerHeight; - } else { - bottom = expItem.getBottom() - childHeight; - top = bottom - dividerHeight; - } - - // Have to clip to support ColorDrawable on <= Gingerbread - canvas.save(); - canvas.clipRect(left, top, right, bottom); - divider.setBounds(left, top, right, bottom); - divider.draw(canvas); - canvas.restore(); - } - } - } - - @Override - protected void dispatchDraw(Canvas canvas) { - super.dispatchDraw(canvas); - - if (mDragState != IDLE) { - // draw the divider over the expanded item - if (mFirstExpPos != mSrcPos) { - drawDivider(mFirstExpPos, canvas); - } - if (mSecondExpPos != mFirstExpPos && mSecondExpPos != mSrcPos) { - drawDivider(mSecondExpPos, canvas); - } - } - - if (mFloatView != null) { - // draw the float view over everything - final int floatViewWidth = mFloatView.getWidth(); - final int floatViewHeight = mFloatView.getHeight(); - - int x = mFloatLoc.x; - - final int listViewWidth = getWidth(); - if (x < 0) - x = -x; - float alphaMod; - if (x < listViewWidth) { - alphaMod = ((float) (listViewWidth - x)) / ((float) listViewWidth); - alphaMod *= alphaMod; - } else { - alphaMod = 0; - } - - final int alpha = (int) (255f * mCurrFloatAlpha * alphaMod); - - canvas.save(); - canvas.translate(mFloatLoc.x, mFloatLoc.y); - canvas.clipRect(0, 0, floatViewWidth, floatViewHeight); - - canvas.saveLayerAlpha(0, 0, floatViewWidth, floatViewHeight, alpha, - Canvas.ALL_SAVE_FLAG); - - mFloatView.draw(canvas); - canvas.restore(); - canvas.restore(); - } - } - - private int getItemHeight(int position) { - View v = getChildAt(position - getFirstVisiblePosition()); - - if (v != null) { - // item is onscreen, just get the height of the View - return v.getHeight(); - } else { - // item is offscreen. get child height and calculate - // item height based on current shuffle state - return calcItemHeight(position, getChildHeight(position)); - } - } - - private class HeightCache { - - private SparseIntArray mMap; - private List mOrder; - private int mMaxSize; - - public HeightCache(int size) { - mMap = new SparseIntArray(size); - mOrder = new ArrayList(size); - mMaxSize = size; - } - - /** - * Add item height at position if doesn't already exist. - */ - public void add(int position, int height) { - int currentHeight = mMap.get(position, -1); - if (currentHeight != height) { - if (currentHeight == -1 && mMap.size() == mMaxSize) { - // remove oldest entry - mMap.delete(mOrder.remove(0)); - } else { - // move position to newest slot - mOrder.remove((Integer) position); - } - mMap.put(position, height); - mOrder.add(position); - } - } - - public int get(int position) { - return mMap.get(position, -1); - } - - public void clear() { - mMap.clear(); - mOrder.clear(); - } - - } - - /** - * Get the shuffle edge for item at position when top of - * item is at y-coord top. Assumes that current item heights - * are consistent with current float view location and - * thus expanded positions and slide fraction. i.e. Should not be - * called between update of expanded positions/slide fraction - * and layoutChildren. - * - * @param position - * @param top - * @param height Height of item at position. If -1, this function - * calculates this height. - * @return Shuffle line between position-1 and position (for - * the given view of the list; that is, for when top of item at - * position has y-coord of given `top`). If - * floating View (treated as horizontal line) is dropped - * immediately above this line, it lands in position-1. If - * dropped immediately below this line, it lands in position. - */ - private int getShuffleEdge(int position, int top) { - final int numHeaders = getHeaderViewsCount(); - final int numFooters = getFooterViewsCount(); - - // shuffle edges are defined between items that can be - // dragged; there are N-1 of them if there are N draggable - // items. - - if (position <= numHeaders || (position >= getCount() - numFooters)) { - return top; - } - - int divHeight = getDividerHeight(); - - int edge; - - int maxBlankHeight = mFloatViewHeight - mItemHeightCollapsed; - int childHeight = getChildHeight(position); - int itemHeight = getItemHeight(position); - - // first calculate top of item given that floating View is - // centered over src position - int otop = top; - if (mSecondExpPos <= mSrcPos) { - // items are expanded on and/or above the source position - - if (position == mSecondExpPos && mFirstExpPos != mSecondExpPos) { - if (position == mSrcPos) { - otop = top + itemHeight - mFloatViewHeight; - } else { - int blankHeight = itemHeight - childHeight; - otop = top + blankHeight - maxBlankHeight; - } - } else if (position > mSecondExpPos && position <= mSrcPos) { - otop = top - maxBlankHeight; - } - - } else { - // items are expanded on and/or below the source position - - if (position > mSrcPos && position <= mFirstExpPos) { - otop = top + maxBlankHeight; - } else if (position == mSecondExpPos && mFirstExpPos != mSecondExpPos) { - int blankHeight = itemHeight - childHeight; - otop = top + blankHeight; - } - } - - // otop is set - if (position <= mSrcPos) { - edge = otop + (mFloatViewHeight - divHeight - getChildHeight(position - 1)) / 2; - } else { - edge = otop + (childHeight - divHeight - mFloatViewHeight) / 2; - } - - return edge; - } - - private boolean updatePositions() { - final int first = getFirstVisiblePosition(); - int startPos = mFirstExpPos; - View startView = getChildAt(startPos - first); - - if (startView == null) { - startPos = first + getChildCount() / 2; - startView = getChildAt(startPos - first); - } - int startTop = startView.getTop(); - - int itemHeight = startView.getHeight(); - - int edge = getShuffleEdge(startPos, startTop); - int lastEdge = edge; - - int divHeight = getDividerHeight(); - - // Log.d("mobeta", "float mid="+mFloatViewMid); - - int itemPos = startPos; - int itemTop = startTop; - if (mFloatViewMid < edge) { - // scanning up for float position - while (itemPos >= 0) { - itemPos--; - itemHeight = getItemHeight(itemPos); - - if (itemPos == 0) { - edge = itemTop - divHeight - itemHeight; - break; - } - - itemTop -= itemHeight + divHeight; - edge = getShuffleEdge(itemPos, itemTop); - - if (mFloatViewMid >= edge) { - break; - } - - lastEdge = edge; - } - } else { - // scanning down for float position - final int count = getCount(); - while (itemPos < count) { - if (itemPos == count - 1) { - edge = itemTop + divHeight + itemHeight; - break; - } - - itemTop += divHeight + itemHeight; - itemHeight = getItemHeight(itemPos + 1); - edge = getShuffleEdge(itemPos + 1, itemTop); - - // test for hit - if (mFloatViewMid < edge) { - break; - } - - lastEdge = edge; - itemPos++; - } - } - - final int numHeaders = getHeaderViewsCount(); - final int numFooters = getFooterViewsCount(); - - boolean updated = false; - - int oldFirstExpPos = mFirstExpPos; - int oldSecondExpPos = mSecondExpPos; - float oldSlideFrac = mSlideFrac; - - if (mAnimate) { - int edgeToEdge = Math.abs(edge - lastEdge); - - int edgeTop, edgeBottom; - if (mFloatViewMid < edge) { - edgeTop = lastEdge; - edgeBottom = edge; - } else { - edgeTop = edge; - edgeBottom = lastEdge; - } - - int slideRgnHeight = (int) (0.5f * mSlideRegionFrac * edgeToEdge); - float slideRgnHeightF = (float) slideRgnHeight; - int slideEdgeTop = edgeTop + slideRgnHeight; - int slideEdgeBottom = edgeBottom - slideRgnHeight; - - // Three regions - if (mFloatViewMid < slideEdgeTop) { - mFirstExpPos = itemPos - 1; - mSecondExpPos = itemPos; - mSlideFrac = 0.5f * ((float) (slideEdgeTop - mFloatViewMid)) / slideRgnHeightF; - } else if (mFloatViewMid < slideEdgeBottom) { - mFirstExpPos = itemPos; - mSecondExpPos = itemPos; - } else { - mFirstExpPos = itemPos; - mSecondExpPos = itemPos + 1; - mSlideFrac = 0.5f * (1.0f + ((float) (edgeBottom - mFloatViewMid)) - / slideRgnHeightF); - } - - } else { - mFirstExpPos = itemPos; - mSecondExpPos = itemPos; - } - - // correct for headers and footers - if (mFirstExpPos < numHeaders) { - itemPos = numHeaders; - mFirstExpPos = itemPos; - mSecondExpPos = itemPos; - } else if (mSecondExpPos >= getCount() - numFooters) { - itemPos = getCount() - numFooters - 1; - mFirstExpPos = itemPos; - mSecondExpPos = itemPos; - } - - if (mFirstExpPos != oldFirstExpPos || mSecondExpPos != oldSecondExpPos - || mSlideFrac != oldSlideFrac) { - updated = true; - } - - if (itemPos != mFloatPos) { - if (mDragListener != null) { - mDragListener.drag(mFloatPos - numHeaders, itemPos - numHeaders); - } - - mFloatPos = itemPos; - updated = true; - } - - return updated; - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - - if (mTrackDragSort) { - mDragSortTracker.appendState(); - } - } - - private class SmoothAnimator implements Runnable { - protected long mStartTime; - - private float mDurationF; - - private float mAlpha; - private float mA, mB, mC, mD; - - private boolean mCanceled; - - public SmoothAnimator(float smoothness, int duration) { - mAlpha = smoothness; - mDurationF = (float) duration; - mA = mD = 1f / (2f * mAlpha * (1f - mAlpha)); - mB = mAlpha / (2f * (mAlpha - 1f)); - mC = 1f / (1f - mAlpha); - } - - public float transform(float frac) { - if (frac < mAlpha) { - return mA * frac * frac; - } else if (frac < 1f - mAlpha) { - return mB + mC * frac; - } else { - return 1f - mD * (frac - 1f) * (frac - 1f); - } - } - - public void start() { - mStartTime = SystemClock.uptimeMillis(); - mCanceled = false; - onStart(); - post(this); - } - - public void cancel() { - mCanceled = true; - } - - public void onStart() { - // stub - } - - public void onUpdate(float frac, float smoothFrac) { - // stub - } - - public void onStop() { - // stub - } - - @Override - public void run() { - if (mCanceled) { - return; - } - - float fraction = ((float) (SystemClock.uptimeMillis() - mStartTime)) / mDurationF; - - if (fraction >= 1f) { - onUpdate(1f, 1f); - onStop(); - } else { - onUpdate(fraction, transform(fraction)); - post(this); - } - } - } - - /** - * Centers floating View under touch point. - */ - private class LiftAnimator extends SmoothAnimator { - - private float mInitDragDeltaY; - private float mFinalDragDeltaY; - - public LiftAnimator(float smoothness, int duration) { - super(smoothness, duration); - } - - @Override - public void onStart() { - mInitDragDeltaY = mDragDeltaY; - mFinalDragDeltaY = mFloatViewHeightHalf; - } - - @Override - public void onUpdate(float frac, float smoothFrac) { - if (mDragState != DRAGGING) { - cancel(); - } else { - mDragDeltaY = (int) (smoothFrac * mFinalDragDeltaY + (1f - smoothFrac) - * mInitDragDeltaY); - mFloatLoc.y = mY - mDragDeltaY; - doDragFloatView(true); - } - } - } - - /** - * Centers floating View over drop slot before destroying. - */ - private class DropAnimator extends SmoothAnimator { - - private int mDropPos; - private int srcPos; - private float mInitDeltaY; - private float mInitDeltaX; - - public DropAnimator(float smoothness, int duration) { - super(smoothness, duration); - } - - @Override - public void onStart() { - mDropPos = mFloatPos; - srcPos = mSrcPos; - mDragState = DROPPING; - mInitDeltaY = mFloatLoc.y - getTargetY(); - mInitDeltaX = mFloatLoc.x - getPaddingLeft(); - } - - private int getTargetY() { - final int first = getFirstVisiblePosition(); - final int otherAdjust = (mItemHeightCollapsed + getDividerHeight()) / 2; - View v = getChildAt(mDropPos - first); - int targetY = -1; - if (v != null) { - if (mDropPos == srcPos) { - targetY = v.getTop(); - } else if (mDropPos < srcPos) { - // expanded down - targetY = v.getTop() - otherAdjust; - } else { - // expanded up - targetY = v.getBottom() + otherAdjust - mFloatViewHeight; - } - } else { - // drop position is not on screen?? no animation - cancel(); - } - - return targetY; - } - - @Override - public void onUpdate(float frac, float smoothFrac) { - final int targetY = getTargetY(); - final int targetX = getPaddingLeft(); - final float deltaY = mFloatLoc.y - targetY; - final float deltaX = mFloatLoc.x - targetX; - final float f = 1f - smoothFrac; - if (f < Math.abs(deltaY / mInitDeltaY) || f < Math.abs(deltaX / mInitDeltaX)) { - mFloatLoc.y = targetY + (int) (mInitDeltaY * f); - mFloatLoc.x = getPaddingLeft() + (int) (mInitDeltaX * f); - doDragFloatView(true); - } - } - - @Override - public void onStop() { - dropFloatView(); - } - - } - - /** - * Collapses expanded items. - */ - private class RemoveAnimator extends SmoothAnimator { - - private float mFloatLocX; - private float mFirstStartBlank; - private float mSecondStartBlank; - - private int mFirstChildHeight = -1; - private int mSecondChildHeight = -1; - - private int mFirstPos; - private int mSecondPos; - - public RemoveAnimator(float smoothness, int duration) { - super(smoothness, duration); - } - - @Override - public void onStart() { - mFirstChildHeight = -1; - mSecondChildHeight = -1; - mFirstPos = mFirstExpPos; - mSecondPos = mSecondExpPos; - mDragState = REMOVING; - - mFloatLocX = mFloatLoc.x; - if (mUseRemoveVelocity) { - float minVelocity = 2f * getWidth(); - if (mRemoveVelocityX == 0) { - mRemoveVelocityX = (mFloatLocX < 0 ? -1 : 1) * minVelocity; - } else { - minVelocity *= 2; - if (mRemoveVelocityX < 0 && mRemoveVelocityX > -minVelocity) - mRemoveVelocityX = -minVelocity; - else if (mRemoveVelocityX > 0 && mRemoveVelocityX < minVelocity) - mRemoveVelocityX = minVelocity; - } - } else { - destroyFloatView(); - } - } - - @Override - public void onUpdate(float frac, float smoothFrac) { - float f = 1f - smoothFrac; - - final int firstVis = getFirstVisiblePosition(); - View item = getChildAt(mFirstPos - firstVis); - ViewGroup.LayoutParams lp; - int blank; - - if (mUseRemoveVelocity) { - float dt = (float) (SystemClock.uptimeMillis() - mStartTime) / 1000; - if (dt == 0) - return; - float dx = mRemoveVelocityX * dt; - int w = getWidth(); - mRemoveVelocityX += (mRemoveVelocityX > 0 ? 1 : -1) * dt * w; - mFloatLocX += dx; - mFloatLoc.x = (int) mFloatLocX; - if (mFloatLocX < w && mFloatLocX > -w) { - mStartTime = SystemClock.uptimeMillis(); - doDragFloatView(true); - return; - } - } - - if (item != null) { - if (mFirstChildHeight == -1) { - mFirstChildHeight = getChildHeight(mFirstPos, item, false); - mFirstStartBlank = (float) (item.getHeight() - mFirstChildHeight); - } - blank = Math.max((int) (f * mFirstStartBlank), 1); - lp = item.getLayoutParams(); - lp.height = mFirstChildHeight + blank; - item.setLayoutParams(lp); - } - if (mSecondPos != mFirstPos) { - item = getChildAt(mSecondPos - firstVis); - if (item != null) { - if (mSecondChildHeight == -1) { - mSecondChildHeight = getChildHeight(mSecondPos, item, false); - mSecondStartBlank = (float) (item.getHeight() - mSecondChildHeight); - } - blank = Math.max((int) (f * mSecondStartBlank), 1); - lp = item.getLayoutParams(); - lp.height = mSecondChildHeight + blank; - item.setLayoutParams(lp); - } - } - } - - @Override - public void onStop() { - doRemoveItem(); - } - } - - public void removeItem(int which) { - mUseRemoveVelocity = false; - removeItem(which, 0); - } - - /** - * Removes an item from the list and animates the removal. - * - * @param which Position to remove (NOTE: headers/footers ignored! - * this is a position in your input ListAdapter). - * @param velocityX - */ - public void removeItem(int which, float velocityX) { - if (mDragState == IDLE || mDragState == DRAGGING) { - if (mDragState == IDLE) { - // called from outside drag-sort - mSrcPos = getHeaderViewsCount() + which; - mFirstExpPos = mSrcPos; - mSecondExpPos = mSrcPos; - mFloatPos = mSrcPos; - View v = getChildAt(mSrcPos - getFirstVisiblePosition()); - if (v != null) { - v.setVisibility(View.INVISIBLE); - } - } - - mDragState = REMOVING; - mRemoveVelocityX = velocityX; - - if (mInTouchEvent) { - switch (mCancelMethod) { - case ON_TOUCH_EVENT: - super.onTouchEvent(mCancelEvent); - break; - case ON_INTERCEPT_TOUCH_EVENT: - super.onInterceptTouchEvent(mCancelEvent); - break; - } - } - - if (mRemoveAnimator != null) { - mRemoveAnimator.start(); - } else { - doRemoveItem(which); - } - } - } - - /** - * Move an item, bypassing the drag-sort process. Simply calls - * through to {@link DropListener#drop(int, int)}. - * - * @param from Position to move (NOTE: headers/footers ignored! - * this is a position in your input ListAdapter). - * @param to Target position (NOTE: headers/footers ignored! - * this is a position in your input ListAdapter). - */ - public void moveItem(int from, int to) { - if (mDropListener != null) { - final int count = getInputAdapter().getCount(); - if (from >= 0 && from < count && to >= 0 && to < count) { - mDropListener.drop(from, to); - } - } - } - - /** - * Cancel a drag. Calls {@link #stopDrag(boolean, boolean)} with - * true as the first argument. - */ - public void cancelDrag() { - if (mDragState == DRAGGING) { - mDragScroller.stopScrolling(true); - destroyFloatView(); - clearPositions(); - adjustAllItems(); - - if (mInTouchEvent) { - mDragState = STOPPED; - } else { - mDragState = IDLE; - } - } - } - - private void clearPositions() { - mSrcPos = -1; - mFirstExpPos = -1; - mSecondExpPos = -1; - mFloatPos = -1; - } - - private void dropFloatView() { - // must set to avoid cancelDrag being called from the DataSetObserver - mDragState = DROPPING; - - if (mDropListener != null && mFloatPos >= 0 && mFloatPos < getCount()) { - final int numHeaders = getHeaderViewsCount(); - mDropListener.drop(mSrcPos - numHeaders, mFloatPos - numHeaders); - } - - destroyFloatView(); - - adjustOnReorder(); - clearPositions(); - adjustAllItems(); - - // now the drag is done - if (mInTouchEvent) { - mDragState = STOPPED; - } else { - mDragState = IDLE; - } - } - - private void doRemoveItem() { - doRemoveItem(mSrcPos - getHeaderViewsCount()); - } - - /** - * Removes dragged item from the list. Calls RemoveListener. - */ - private void doRemoveItem(int which) { - // must set to avoid cancelDrag being called from the DataSetObserver - mDragState = REMOVING; - - // end it - if (mRemoveListener != null) { - mRemoveListener.remove(which); - } - - destroyFloatView(); - - adjustOnReorder(); - clearPositions(); - - // now the drag is done - if (mInTouchEvent) { - mDragState = STOPPED; - } else { - mDragState = IDLE; - } - } - - private void adjustOnReorder() { - final int firstPos = getFirstVisiblePosition(); - if (mSrcPos < firstPos) { - // collapsed src item is off screen; - // adjust the scroll after item heights have been fixed - View v = getChildAt(0); - int top = 0; - if (v != null) { - top = v.getTop(); - } - setSelectionFromTop(firstPos - 1, top - getPaddingTop()); - } - } - - /** - * Stop a drag in progress. Pass true if you would - * like to remove the dragged item from the list. - * - * @param remove Remove the dragged item from the list. Calls - * a registered RemoveListener, if one exists. Otherwise, calls - * the DropListener, if one exists. - * @return True if the stop was successful. False if there is - * no floating View. - */ - public boolean stopDrag(boolean remove) { - mUseRemoveVelocity = false; - return stopDrag(remove, 0); - } - - public boolean stopDragWithVelocity(boolean remove, float velocityX) { - mUseRemoveVelocity = true; - return stopDrag(remove, velocityX); - } - - public boolean stopDrag(boolean remove, float velocityX) { - if (mFloatView != null) { - mDragScroller.stopScrolling(true); - - if (remove) { - removeItem(mSrcPos - getHeaderViewsCount(), velocityX); - } else { - if (mDropAnimator != null) { - mDropAnimator.start(); - } else { - dropFloatView(); - } - } - - if (mTrackDragSort) { - mDragSortTracker.stopTracking(); - } - - return true; - } else { - // stop failed - return false; - } - } - - @Override - public boolean onTouchEvent(MotionEvent ev) { - if (mIgnoreTouchEvent) { - mIgnoreTouchEvent = false; - return false; - } - - if (!mDragEnabled) { - return super.onTouchEvent(ev); - } - - boolean more = false; - - boolean lastCallWasIntercept = mLastCallWasIntercept; - mLastCallWasIntercept = false; - - if (!lastCallWasIntercept) { - saveTouchCoords(ev); - } - - if (mDragState == DRAGGING) { - onDragTouchEvent(ev); - more = true; // give us more! - } else { - // TODO: what if float view is null because we dropped in middle - // of drag touch event? - - if (mDragState == IDLE) { - if (super.onTouchEvent(ev)) { - more = true; - } - } - - int action = ev.getAction() & MotionEvent.ACTION_MASK; - - switch (action) { - case MotionEvent.ACTION_CANCEL: - case MotionEvent.ACTION_UP: - doActionUpOrCancel(); - break; - default: - if (more) { - mCancelMethod = ON_TOUCH_EVENT; - } - } - } - - return more; - } - - private void doActionUpOrCancel() { - mCancelMethod = NO_CANCEL; - mInTouchEvent = false; - if (mDragState == STOPPED) { - mDragState = IDLE; - } - mCurrFloatAlpha = mFloatAlpha; - mListViewIntercepted = false; - mChildHeightCache.clear(); - } - - private void saveTouchCoords(MotionEvent ev) { - int action = ev.getAction() & MotionEvent.ACTION_MASK; - if (action != MotionEvent.ACTION_DOWN) { - //mLastX = mX; - mLastY = mY; - } - mX = (int) ev.getX(); - mY = (int) ev.getY(); - if (action == MotionEvent.ACTION_DOWN) { - //mLastX = mX; - mLastY = mY; - } - //mOffsetX = (int) ev.getRawX() - mX; - //mOffsetY = (int) ev.getRawY() - mY; - } - - public boolean listViewIntercepted() { - return mListViewIntercepted; - } - - private boolean mListViewIntercepted = false; - - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - if (!mDragEnabled) { - return super.onInterceptTouchEvent(ev); - } - - saveTouchCoords(ev); - mLastCallWasIntercept = true; - - int action = ev.getAction() & MotionEvent.ACTION_MASK; - - if (action == MotionEvent.ACTION_DOWN) { - if (mDragState != IDLE) { - // intercept and ignore - mIgnoreTouchEvent = true; - return true; - } - mInTouchEvent = true; - } - - boolean intercept = false; - - // the following deals with calls to super.onInterceptTouchEvent - if (mFloatView != null) { - // super's touch event cancelled in startDrag - intercept = true; - } else { - if (super.onInterceptTouchEvent(ev)) { - mListViewIntercepted = true; - intercept = true; - } - - switch (action) { - case MotionEvent.ACTION_CANCEL: - case MotionEvent.ACTION_UP: - doActionUpOrCancel(); - break; - default: - if (intercept) { - mCancelMethod = ON_TOUCH_EVENT; - } else { - mCancelMethod = ON_INTERCEPT_TOUCH_EVENT; - } - } - } - - if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { - mInTouchEvent = false; - } - - return intercept; - } - - /** - * Set the width of each drag scroll region by specifying - * a fraction of the ListView height. - * - * @param heightFraction Fraction of ListView height. Capped at - * 0.5f. - */ - public void setDragScrollStart(float heightFraction) { - setDragScrollStarts(heightFraction, heightFraction); - } - - /** - * Set the width of each drag scroll region by specifying - * a fraction of the ListView height. - * - * @param upperFrac Fraction of ListView height for up-scroll bound. - * Capped at 0.5f. - * @param lowerFrac Fraction of ListView height for down-scroll bound. - * Capped at 0.5f. - */ - public void setDragScrollStarts(float upperFrac, float lowerFrac) { - if (lowerFrac > 0.5f) { - mDragDownScrollStartFrac = 0.5f; - } else { - mDragDownScrollStartFrac = lowerFrac; - } - - if (upperFrac > 0.5f) { - mDragUpScrollStartFrac = 0.5f; - } else { - mDragUpScrollStartFrac = upperFrac; - } - - if (getHeight() != 0) { - updateScrollStarts(); - } - } - - private void continueDrag(int x, int y) { - // proposed position - mFloatLoc.x = x - mDragDeltaX; - mFloatLoc.y = y - mDragDeltaY; - - doDragFloatView(true); - - int minY = Math.min(y, mFloatViewMid + mFloatViewHeightHalf); - int maxY = Math.max(y, mFloatViewMid - mFloatViewHeightHalf); - - // get the current scroll direction - int currentScrollDir = mDragScroller.getScrollDir(); - - if (minY > mLastY && minY > mDownScrollStartY && currentScrollDir != DragScroller.DOWN) { - // dragged down, it is below the down scroll start and it is not - // scrolling up - - if (currentScrollDir != DragScroller.STOP) { - // moved directly from up scroll to down scroll - mDragScroller.stopScrolling(true); - } - - // start scrolling down - mDragScroller.startScrolling(DragScroller.DOWN); - } else if (maxY < mLastY && maxY < mUpScrollStartY && currentScrollDir != DragScroller.UP) { - // dragged up, it is above the up scroll start and it is not - // scrolling up - - if (currentScrollDir != DragScroller.STOP) { - // moved directly from down scroll to up scroll - mDragScroller.stopScrolling(true); - } - - // start scrolling up - mDragScroller.startScrolling(DragScroller.UP); - } else if (maxY >= mUpScrollStartY && minY <= mDownScrollStartY - && mDragScroller.isScrolling()) { - // not in the upper nor in the lower drag-scroll regions but it is - // still scrolling - - mDragScroller.stopScrolling(true); - } - } - - private void updateScrollStarts() { - final int padTop = getPaddingTop(); - final int listHeight = getHeight() - padTop - getPaddingBottom(); - float heightF = (float) listHeight; - - mUpScrollStartYF = padTop + mDragUpScrollStartFrac * heightF; - mDownScrollStartYF = padTop + (1.0f - mDragDownScrollStartFrac) * heightF; - - mUpScrollStartY = (int) mUpScrollStartYF; - mDownScrollStartY = (int) mDownScrollStartYF; - - mDragUpScrollHeight = mUpScrollStartYF - padTop; - mDragDownScrollHeight = padTop + listHeight - mDownScrollStartYF; - } - - @Override - protected void onSizeChanged(int w, int h, int oldw, int oldh) { - super.onSizeChanged(w, h, oldw, oldh); - updateScrollStarts(); - } - - private void adjustAllItems() { - final int first = getFirstVisiblePosition(); - final int last = getLastVisiblePosition(); - - int begin = Math.max(0, getHeaderViewsCount() - first); - int end = Math.min(last - first, getCount() - 1 - getFooterViewsCount() - first); - - for (int i = begin; i <= end; ++i) { - View v = getChildAt(i); - if (v != null) { - adjustItem(first + i, v, false); - } - } - } - - /** - * Sets layout param height, gravity, and visibility on - * wrapped item. - */ - private void adjustItem(int position, View v, boolean invalidChildHeight) { - // Adjust item height - ViewGroup.LayoutParams lp = v.getLayoutParams(); - int height; - if (position != mSrcPos && position != mFirstExpPos && position != mSecondExpPos) { - height = ViewGroup.LayoutParams.WRAP_CONTENT; - } else { - height = calcItemHeight(position, v, invalidChildHeight); - } - - if (height != lp.height) { - lp.height = height; - v.setLayoutParams(lp); - } - - // Adjust item gravity - if (position == mFirstExpPos || position == mSecondExpPos) { - if (position < mSrcPos) { - ((DragSortItemView) v).setGravity(Gravity.BOTTOM); - } else if (position > mSrcPos) { - ((DragSortItemView) v).setGravity(Gravity.TOP); - } - } - - // Finally adjust item visibility - int oldVis = v.getVisibility(); - int vis = View.VISIBLE; - - if (position == mSrcPos && mFloatView != null) { - vis = View.INVISIBLE; - } - - if (vis != oldVis) { - v.setVisibility(vis); - } - } - - private int getChildHeight(int position) { - if (position == mSrcPos) { - return 0; - } - - View v = getChildAt(position - getFirstVisiblePosition()); - - if (v != null) { - // item is onscreen, therefore child height is valid, - // hence the "true" - return getChildHeight(position, v, false); - } else { - // item is offscreen - // first check cache for child height at this position - int childHeight = mChildHeightCache.get(position); - if (childHeight != -1) { - return childHeight; - } - - final ListAdapter adapter = getAdapter(); - int type = adapter.getItemViewType(position); - - // There might be a better place for checking for the following - final int typeCount = adapter.getViewTypeCount(); - if (typeCount != mSampleViewTypes.length) { - mSampleViewTypes = new View[typeCount]; - } - - if (type >= 0) { - if (mSampleViewTypes[type] == null) { - v = adapter.getView(position, null, this); - mSampleViewTypes[type] = v; - } else { - v = adapter.getView(position, mSampleViewTypes[type], this); - } - } else { - // type is HEADER_OR_FOOTER or IGNORE - v = adapter.getView(position, null, this); - } - - // current child height is invalid, hence "true" below - childHeight = getChildHeight(position, v, true); - - // cache it because this could have been expensive - mChildHeightCache.add(position, childHeight); - - return childHeight; - } - } - - private int getChildHeight(int position, View item, boolean invalidChildHeight) { - if (position == mSrcPos) { - return 0; - } - - View child; - if (position < getHeaderViewsCount() || position >= getCount() - getFooterViewsCount()) { - child = item; - } else { - child = ((ViewGroup) item).getChildAt(0); - } - - ViewGroup.LayoutParams lp = child.getLayoutParams(); - if (lp != null) { - if (lp.height > 0) { - return lp.height; - } - } - - int childHeight = child.getHeight(); - if (childHeight == 0 || invalidChildHeight) { - measureItem(child); - childHeight = child.getMeasuredHeight(); - } - - return childHeight; - } - - private int calcItemHeight(int position, View item, boolean invalidChildHeight) { - return calcItemHeight(position, getChildHeight(position, item, invalidChildHeight)); - } - - private int calcItemHeight(int position, int childHeight) { - boolean isSliding = mAnimate && mFirstExpPos != mSecondExpPos; - int maxNonSrcBlankHeight = mFloatViewHeight - mItemHeightCollapsed; - int slideHeight = (int) (mSlideFrac * maxNonSrcBlankHeight); - - int height; - - if (position == mSrcPos) { - if (mSrcPos == mFirstExpPos) { - if (isSliding) { - height = slideHeight + mItemHeightCollapsed; - } else { - height = mFloatViewHeight; - } - } else if (mSrcPos == mSecondExpPos) { - // if gets here, we know an item is sliding - height = mFloatViewHeight - slideHeight; - } else { - height = mItemHeightCollapsed; - } - } else if (position == mFirstExpPos) { - if (isSliding) { - height = childHeight + slideHeight; - } else { - height = childHeight + maxNonSrcBlankHeight; - } - } else if (position == mSecondExpPos) { - // we know an item is sliding (b/c 2ndPos != 1stPos) - height = childHeight + maxNonSrcBlankHeight - slideHeight; - } else { - height = childHeight; - } - - return height; - } - - @Override - public void requestLayout() { - if (!mBlockLayoutRequests) { - super.requestLayout(); - } - } - - private int adjustScroll(int movePos, View moveItem, int oldFirstExpPos, int oldSecondExpPos) { - int adjust = 0; - - final int childHeight = getChildHeight(movePos); - - int moveHeightBefore = moveItem.getHeight(); - int moveHeightAfter = calcItemHeight(movePos, childHeight); - - int moveBlankBefore = moveHeightBefore; - int moveBlankAfter = moveHeightAfter; - if (movePos != mSrcPos) { - moveBlankBefore -= childHeight; - moveBlankAfter -= childHeight; - } - - int maxBlank = mFloatViewHeight; - if (mSrcPos != mFirstExpPos && mSrcPos != mSecondExpPos) { - maxBlank -= mItemHeightCollapsed; - } - - if (movePos <= oldFirstExpPos) { - if (movePos > mFirstExpPos) { - adjust += maxBlank - moveBlankAfter; - } - } else if (movePos == oldSecondExpPos) { - if (movePos <= mFirstExpPos) { - adjust += moveBlankBefore - maxBlank; - } else if (movePos == mSecondExpPos) { - adjust += moveHeightBefore - moveHeightAfter; - } else { - adjust += moveBlankBefore; - } - } else { - if (movePos <= mFirstExpPos) { - adjust -= maxBlank; - } else if (movePos == mSecondExpPos) { - adjust -= moveBlankAfter; - } - } - - return adjust; - } - - private void measureItem(View item) { - ViewGroup.LayoutParams lp = item.getLayoutParams(); - if (lp == null) { - lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT); - item.setLayoutParams(lp); - } - - int wspec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec, getListPaddingLeft() - + getListPaddingRight(), lp.width); - int hspec; - if (lp.height > 0) { - hspec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); - } else { - hspec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); - } - item.measure(wspec, hspec); - } - - private void measureFloatView() { - if (mFloatView != null) { - measureItem(mFloatView); - mFloatViewHeight = mFloatView.getMeasuredHeight(); - mFloatViewHeightHalf = mFloatViewHeight / 2; - } - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - if (mFloatView != null) { - if (mFloatView.isLayoutRequested()) { - measureFloatView(); - } - mFloatViewOnMeasured = true; // set to false after layout - } - mWidthMeasureSpec = widthMeasureSpec; - } - - @Override - protected void layoutChildren() { - super.layoutChildren(); - - if (mFloatView != null) { - if (mFloatView.isLayoutRequested() && !mFloatViewOnMeasured) { - // Have to measure here when usual android measure - // pass is skipped. This happens during a drag-sort - // when layoutChildren is called directly. - measureFloatView(); - } - mFloatView.layout(0, 0, mFloatView.getMeasuredWidth(), mFloatView.getMeasuredHeight()); - mFloatViewOnMeasured = false; - } - } - - protected boolean onDragTouchEvent(MotionEvent ev) { - int action = ev.getAction() & MotionEvent.ACTION_MASK; - switch (action) { - case MotionEvent.ACTION_CANCEL: - if (mDragState == DRAGGING) { - cancelDrag(); - } - doActionUpOrCancel(); - break; - case MotionEvent.ACTION_UP: - if (mDragState == DRAGGING) { - stopDrag(false); - } - doActionUpOrCancel(); - break; - case MotionEvent.ACTION_MOVE: - continueDrag((int) ev.getX(), (int) ev.getY()); - break; - } - - return true; - } - - /** - * Start a drag of item at position using the - * registered FloatViewManager. Calls through - * to {@link #startDrag(int, View, int, int, int)} after obtaining - * the floating View from the FloatViewManager. - * - * @param position Item to drag. - * @param dragFlags Flags that restrict some movements of the - * floating View. For example, set dragFlags |= - * ~{@link #DRAG_NEG_X} to allow dragging the floating - * View in all directions except off the screen to the left. - * @param deltaX Offset in x of the touch coordinate from the - * left edge of the floating View (i.e. touch-x minus float View - * left). - * @param deltaY Offset in y of the touch coordinate from the - * top edge of the floating View (i.e. touch-y minus float View - * top). - * @return True if the drag was started, false otherwise. This - * startDrag will fail if we are not currently in - * a touch event, there is no registered FloatViewManager, - * or the FloatViewManager returns a null View. - */ - public boolean startDrag(int position, int dragFlags, int deltaX, int deltaY) { - if (!mInTouchEvent || mFloatViewManager == null) { - return false; - } - - View v = mFloatViewManager.onCreateFloatView(position); - - if (v == null) { - return false; - } else { - return startDrag(position, v, dragFlags, deltaX, deltaY); - } - - } - - /** - * Start a drag of item at position without using - * a FloatViewManager. - * - * @param position Item to drag. - * @param floatView Floating View. - * @param dragFlags Flags that restrict some movements of the - * floating View. For example, set dragFlags |= - * ~{@link #DRAG_NEG_X} to allow dragging the floating - * View in all directions except off the screen to the left. - * @param deltaX Offset in x of the touch coordinate from the - * left edge of the floating View (i.e. touch-x minus float View - * left). - * @param deltaY Offset in y of the touch coordinate from the - * top edge of the floating View (i.e. touch-y minus float View - * top). - * @return True if the drag was started, false otherwise. This - * startDrag will fail if we are not currently in - * a touch event, floatView is null, or there is - * a drag in progress. - */ - public boolean startDrag(int position, View floatView, int dragFlags, int deltaX, int deltaY) { - if (mDragState != IDLE || !mInTouchEvent || mFloatView != null || floatView == null - || !mDragEnabled) { - return false; - } - - if (getParent() != null) { - getParent().requestDisallowInterceptTouchEvent(true); - } - - int pos = position + getHeaderViewsCount(); - mFirstExpPos = pos; - mSecondExpPos = pos; - mSrcPos = pos; - mFloatPos = pos; - - mDragState = DRAGGING; - mDragFlags = 0; - mDragFlags |= dragFlags; - - mFloatView = floatView; - measureFloatView(); // sets mFloatViewHeight - - mDragDeltaX = deltaX; - mDragDeltaY = deltaY; - - mFloatLoc.x = mX - mDragDeltaX; - mFloatLoc.y = mY - mDragDeltaY; - - // set src item invisible - final View srcItem = getChildAt(mSrcPos - getFirstVisiblePosition()); - - if (srcItem != null) { - srcItem.setVisibility(View.INVISIBLE); - } - - if (mTrackDragSort) { - mDragSortTracker.startTracking(); - } - - // once float view is created, events are no longer passed - // to ListView - switch (mCancelMethod) { - case ON_TOUCH_EVENT: - super.onTouchEvent(mCancelEvent); - break; - case ON_INTERCEPT_TOUCH_EVENT: - super.onInterceptTouchEvent(mCancelEvent); - break; - } - - requestLayout(); - - if (mLiftAnimator != null) { - mLiftAnimator.start(); - } - - return true; - } - - private void doDragFloatView(boolean forceInvalidate) { - int movePos = getFirstVisiblePosition() + getChildCount() / 2; - View moveItem = getChildAt(getChildCount() / 2); - - if (moveItem == null) { - return; - } - - doDragFloatView(movePos, moveItem, forceInvalidate); - } - - private void doDragFloatView(int movePos, View moveItem, boolean forceInvalidate) { - mBlockLayoutRequests = true; - - updateFloatView(); - - int oldFirstExpPos = mFirstExpPos; - int oldSecondExpPos = mSecondExpPos; - - boolean updated = updatePositions(); - - if (updated) { - adjustAllItems(); - int scroll = adjustScroll(movePos, moveItem, oldFirstExpPos, oldSecondExpPos); - - setSelectionFromTop(movePos, moveItem.getTop() + scroll - getPaddingTop()); - layoutChildren(); - } - - if (updated || forceInvalidate) { - invalidate(); - } - - mBlockLayoutRequests = false; - } - - /** - * Sets float View location based on suggested values and - * constraints set in mDragFlags. - */ - private void updateFloatView() { - - if (mFloatViewManager != null) { - mTouchLoc.set(mX, mY); - mFloatViewManager.onDragFloatView(mFloatView, mFloatLoc, mTouchLoc); - } - - final int floatX = mFloatLoc.x; - final int floatY = mFloatLoc.y; - - // restrict x motion - int padLeft = getPaddingLeft(); - if ((mDragFlags & DRAG_POS_X) == 0 && floatX > padLeft) { - mFloatLoc.x = padLeft; - } else if ((mDragFlags & DRAG_NEG_X) == 0 && floatX < padLeft) { - mFloatLoc.x = padLeft; - } - - // keep floating view from going past bottom of last header view - final int numHeaders = getHeaderViewsCount(); - final int numFooters = getFooterViewsCount(); - final int firstPos = getFirstVisiblePosition(); - final int lastPos = getLastVisiblePosition(); - - int topLimit = getPaddingTop(); - if (firstPos < numHeaders) { - topLimit = getChildAt(numHeaders - firstPos - 1).getBottom(); - } - if ((mDragFlags & DRAG_NEG_Y) == 0) { - if (firstPos <= mSrcPos) { - topLimit = Math.max(getChildAt(mSrcPos - firstPos).getTop(), topLimit); - } - } - // bottom limit is top of first footer View or - // bottom of last item in list - int bottomLimit = getHeight() - getPaddingBottom(); - if (lastPos >= getCount() - numFooters - 1) { - bottomLimit = getChildAt(getCount() - numFooters - 1 - firstPos).getBottom(); - } - if ((mDragFlags & DRAG_POS_Y) == 0) { - if (lastPos >= mSrcPos) { - bottomLimit = Math.min(getChildAt(mSrcPos - firstPos).getBottom(), bottomLimit); - } - } - - if (floatY < topLimit) { - mFloatLoc.y = topLimit; - } else if (floatY + mFloatViewHeight > bottomLimit) { - mFloatLoc.y = bottomLimit - mFloatViewHeight; - } - - // get y-midpoint of floating view (constrained to ListView bounds) - mFloatViewMid = mFloatLoc.y + mFloatViewHeightHalf; - } - - private void destroyFloatView() { - if (mFloatView != null) { - mFloatView.setVisibility(GONE); - if (mFloatViewManager != null) { - mFloatViewManager.onDestroyFloatView(mFloatView); - } - mFloatView = null; - invalidate(); - } - } - - /** - * Interface for customization of the floating View appearance - * and dragging behavior. Implement - * your own and pass it to {@link #setFloatViewManager}. If - * your own is not passed, the default {@link SimpleFloatViewManager} - * implementation is used. - */ - public interface FloatViewManager { - /** - * Return the floating View for item at position. - * DragSortListView will measure and layout this View for you, - * so feel free to just inflate it. You can help DSLV by - * setting some {@link ViewGroup.LayoutParams} on this View; - * otherwise it will set some for you (with a width of FILL_PARENT - * and a height of WRAP_CONTENT). - * - * @param position Position of item to drag (NOTE: - * position excludes header Views; thus, if you - * want to call {@link ListView#getChildAt(int)}, you will need - * to add {@link ListView#getHeaderViewsCount()} to the index). - * @return The View you wish to display as the floating View. - */ - public View onCreateFloatView(int position); - - /** - * Called whenever the floating View is dragged. Float View - * properties can be changed here. Also, the upcoming location - * of the float View can be altered by setting - * location.x and location.y. - * - * @param floatView The floating View. - * @param location The location (top-left; relative to DSLV - * top-left) at which the float - * View would like to appear, given the current touch location - * and the offset provided in {@link DragSortListView#startDrag}. - * @param touch The current touch location (relative to DSLV - * top-left). - * @param pendingScroll - */ - public void onDragFloatView(View floatView, Point location, Point touch); - - /** - * Called when the float View is dropped; lets you perform - * any necessary cleanup. The internal DSLV floating View - * reference is set to null immediately after this is called. - * - * @param floatView The floating View passed to - * {@link #onCreateFloatView(int)}. - */ - public void onDestroyFloatView(View floatView); - } - - public void setFloatViewManager(FloatViewManager manager) { - mFloatViewManager = manager; - } - - public void setDragListener(DragListener l) { - mDragListener = l; - } - - /** - * Allows for easy toggling between a DragSortListView - * and a regular old ListView. If enabled, items are - * draggable, where the drag init mode determines how - * items are lifted (see {@link setDragInitMode(int)}). - * If disabled, items cannot be dragged. - * - * @param enabled Set true to enable list - * item dragging - */ - public void setDragEnabled(boolean enabled) { - mDragEnabled = enabled; - } - - public boolean isDragEnabled() { - return mDragEnabled; - } - - /** - * This better reorder your ListAdapter! DragSortListView does not do this - * for you; doesn't make sense to. Make sure - * {@link BaseAdapter#notifyDataSetChanged()} or something like it is called - * in your implementation. Furthermore, if you have a choiceMode other than - * none and the ListAdapter does not return true for - * {@link ListAdapter#hasStableIds()}, you will need to call - * {@link #moveCheckState(int, int)} to move the check boxes along with the - * list items. - * - * @param l - */ - public void setDropListener(DropListener l) { - mDropListener = l; - } - - /** - * Probably a no-brainer, but make sure that your remove listener - * calls {@link BaseAdapter#notifyDataSetChanged()} or something like it. - * When an item removal occurs, DragSortListView - * relies on a redraw of all the items to recover invisible views - * and such. Strictly speaking, if you remove something, your dataset - * has changed... - * - * @param l - */ - public void setRemoveListener(RemoveListener l) { - mRemoveListener = l; - } - - public interface DragListener { - public void drag(int from, int to); - } - - /** - * Your implementation of this has to reorder your ListAdapter! - * Make sure to call - * {@link BaseAdapter#notifyDataSetChanged()} or something like it - * in your implementation. - * - * @author heycosmo - */ - public interface DropListener { - public void drop(int from, int to); - } - - /** - * Make sure to call - * {@link BaseAdapter#notifyDataSetChanged()} or something like it - * in your implementation. - * - * @author heycosmo - */ - public interface RemoveListener { - public void remove(int which); - } - - public interface DragSortListener extends DropListener, DragListener, RemoveListener { - } - - public void setDragSortListener(DragSortListener listener) { - setDropListener(listener); - setDragListener(listener); - setRemoveListener(listener); - } - - /** - * Completely custom scroll speed profile. Default increases linearly - * with position and is constant in time. Create your own by implementing - * {@link DragSortListView.DragScrollProfile}. - * - * @param scrollProfile - */ - public void setDragScrollProfile(DragScrollProfile scrollProfile) { - if (scrollProfile != null) { - mScrollProfile = scrollProfile; - } - } - - /** - * Use this to move the check state of an item from one position to another - * in a drop operation. If you have a choiceMode which is not none, this - * method must be called when the order of items changes in an underlying - * adapter which does not have stable IDs (see - * {@link ListAdapter#hasStableIds()}). This is because without IDs, the - * ListView has no way of knowing which items have moved where, and cannot - * update the check state accordingly. - *

- * A word of warning about a "feature" in Android that you may run into when - * dealing with movable list items: for an adapter that does have - * stable IDs, ListView will attempt to locate each item based on its ID and - * move the check state from the item's old position to the new position — - * which is all fine and good (and removes the need for calling this - * function), except for the half-baked approach. Apparently to save time in - * the naive algorithm used, ListView will only search for an ID in the - * close neighborhood of the old position. If the user moves an item too far - * (specifically, more than 20 rows away), ListView will give up and just - * force the item to be unchecked. So if there is a reasonable chance that - * the user will move items more than 20 rows away from the original - * position, you may wish to use an adapter with unstable IDs and call this - * method manually instead. - * - * @param from - * @param to - */ - public void moveCheckState(int from, int to) { - // This method runs in O(n log n) time (n being the number of list - // items). The bottleneck is the call to AbsListView.setItemChecked, - // which is O(log n) because of the binary search involved in calling - // SparseBooleanArray.put(). - // - // To improve on the average time, we minimize the number of calls to - // setItemChecked by only calling it for items that actually have a - // changed state. This is achieved by building a list containing the - // start and end of the "runs" of checked items, and then moving the - // runs. Note that moving an item from A to B is essentially a rotation - // of the range of items in [A, B]. Let's say we have - // . . U V X Y Z . . - // and move U after Z. This is equivalent to a rotation one step to the - // left within the range you are moving across: - // . . V X Y Z U . . - // - // So, to perform the move we enumerate all the runs within the move - // range, then rotate each run one step to the left or right (depending - // on move direction). For example, in the list: - // X X . X X X . X - // we have two runs. One begins at the last item of the list and wraps - // around to the beginning, ending at position 1. The second begins at - // position 3 and ends at position 5. To rotate a run, regardless of - // length, we only need to set a check mark at one end of the run, and - // clear a check mark at the other end: - // X . X X X . X X - SparseBooleanArray cip = getCheckedItemPositions(); - int rangeStart = from; - int rangeEnd = to; - if (to < from) { - rangeStart = to; - rangeEnd = from; - } - rangeEnd += 1; - - int[] runStart = new int[cip.size()]; - int[] runEnd = new int[cip.size()]; - int runCount = buildRunList(cip, rangeStart, rangeEnd, runStart, runEnd); - if (runCount == 1 && (runStart[0] == runEnd[0])) { - // Special case where all items are checked, we can never set any - // item to false like we do below. - return; - } - - if (from < to) { - for (int i = 0; i != runCount; i++) { - setItemChecked(rotate(runStart[i], -1, rangeStart, rangeEnd), true); - setItemChecked(rotate(runEnd[i], -1, rangeStart, rangeEnd), false); - } - - } else { - for (int i = 0; i != runCount; i++) { - setItemChecked(runStart[i], false); - setItemChecked(runEnd[i], true); - } - } - } - - /** - * Use this when an item has been deleted, to move the check state of all - * following items up one step. If you have a choiceMode which is not none, - * this method must be called when the order of items changes in an - * underlying adapter which does not have stable IDs (see - * {@link ListAdapter#hasStableIds()}). This is because without IDs, the - * ListView has no way of knowing which items have moved where, and cannot - * update the check state accordingly. - *

- * See also further comments on {@link #moveCheckState(int, int)}. - * - * @param position - */ - public void removeCheckState(int position) { - SparseBooleanArray cip = getCheckedItemPositions(); - - if (cip.size() == 0) - return; - int[] runStart = new int[cip.size()]; - int[] runEnd = new int[cip.size()]; - int rangeStart = position; - int rangeEnd = cip.keyAt(cip.size() - 1) + 1; - int runCount = buildRunList(cip, rangeStart, rangeEnd, runStart, runEnd); - for (int i = 0; i != runCount; i++) { - if (!(runStart[i] == position || (runEnd[i] < runStart[i] && runEnd[i] > position))) { - // Only set a new check mark in front of this run if it does - // not contain the deleted position. If it does, we only need - // to make it one check mark shorter at the end. - setItemChecked(rotate(runStart[i], -1, rangeStart, rangeEnd), true); - } - setItemChecked(rotate(runEnd[i], -1, rangeStart, rangeEnd), false); - } - } - - private static int buildRunList(SparseBooleanArray cip, int rangeStart, int rangeEnd, - int[] runStart, int[] runEnd) { - - int runCount = 0; - - int i = findFirstSetIndex(cip, rangeStart, rangeEnd); - if (i == -1) - return 0; - - int position = cip.keyAt(i); - int currentRunStart = position; - int currentRunEnd = currentRunStart + 1; - for (i++; i < cip.size() && (position = cip.keyAt(i)) < rangeEnd; i++) { - if (!cip.valueAt(i)) // not checked => not interesting - continue; - if (position == currentRunEnd) { - currentRunEnd++; - } else { - runStart[runCount] = currentRunStart; - runEnd[runCount] = currentRunEnd; - runCount++; - currentRunStart = position; - currentRunEnd = position + 1; - } - } - - if (currentRunEnd == rangeEnd) { - // rangeStart and rangeEnd are equivalent positions so to be - // consistent we translate them to the same integer value. That way - // we can check whether a run covers the entire range by just - // checking if the start equals the end position. - currentRunEnd = rangeStart; - } - runStart[runCount] = currentRunStart; - runEnd[runCount] = currentRunEnd; - runCount++; - - if (runCount > 1) { - if (runStart[0] == rangeStart && runEnd[runCount - 1] == rangeStart) { - // The last run ends at the end of the range, and the first run - // starts at the beginning of the range. So they are actually - // part of the same run, except they wrap around the end of the - // range. To avoid adjacent runs, we need to merge them. - runStart[0] = runStart[runCount - 1]; - runCount--; - } - } - return runCount; - } - - private static int rotate(int value, int offset, int lowerBound, int upperBound) { - int windowSize = upperBound - lowerBound; - - value += offset; - if (value < lowerBound) { - value += windowSize; - } else if (value >= upperBound) { - value -= windowSize; - } - return value; - } - - private static int findFirstSetIndex(SparseBooleanArray sba, int rangeStart, int rangeEnd) { - int size = sba.size(); - int i = insertionIndexForKey(sba, rangeStart); - while (i < size && sba.keyAt(i) < rangeEnd && !sba.valueAt(i)) - i++; - if (i == size || sba.keyAt(i) >= rangeEnd) - return -1; - return i; - } - - private static int insertionIndexForKey(SparseBooleanArray sba, int key) { - int low = 0; - int high = sba.size(); - while (high - low > 0) { - int middle = (low + high) >> 1; - if (sba.keyAt(middle) < key) - low = middle + 1; - else - high = middle; - } - return low; - } - - /** - * Interface for controlling - * scroll speed as a function of touch position and time. Use - * {@link DragSortListView#setDragScrollProfile(DragScrollProfile)} to - * set custom profile. - * - * @author heycosmo - */ - public interface DragScrollProfile { - /** - * Return a scroll speed in pixels/millisecond. Always return a - * positive number. - * - * @param w Normalized position in scroll region (i.e. w \in [0,1]). - * Small w typically means slow scrolling. - * @param t Time (in milliseconds) since start of scroll (handy if you - * want scroll acceleration). - * @return Scroll speed at position w and time t in pixels/ms. - */ - float getSpeed(float w, long t); - } - - private class DragScroller implements Runnable { - - private boolean mAbort; - - private long mPrevTime; - private long mCurrTime; - - private int dy; - private float dt; - private long tStart; - private int scrollDir; - - public final static int STOP = -1; - public final static int UP = 0; - public final static int DOWN = 1; - - private float mScrollSpeed; // pixels per ms - - private boolean mScrolling = false; - - public boolean isScrolling() { - return mScrolling; - } - - public int getScrollDir() { - return mScrolling ? scrollDir : STOP; - } - - public DragScroller() { - } - - public void startScrolling(int dir) { - if (!mScrolling) { - mAbort = false; - mScrolling = true; - tStart = SystemClock.uptimeMillis(); - mPrevTime = tStart; - scrollDir = dir; - post(this); - } - } - - public void stopScrolling(boolean now) { - if (now) { - DragSortListView.this.removeCallbacks(this); - mScrolling = false; - } else { - mAbort = true; - } - } - - @Override - public void run() { - if (mAbort) { - mScrolling = false; - return; - } - - final int first = getFirstVisiblePosition(); - final int last = getLastVisiblePosition(); - final int count = getCount(); - final int padTop = getPaddingTop(); - final int listHeight = getHeight() - padTop - getPaddingBottom(); - - int minY = Math.min(mY, mFloatViewMid + mFloatViewHeightHalf); - int maxY = Math.max(mY, mFloatViewMid - mFloatViewHeightHalf); - - if (scrollDir == UP) { - View v = getChildAt(0); - if (v == null) { - mScrolling = false; - return; - } else { - if (first == 0 && v.getTop() == padTop) { - mScrolling = false; - return; - } - } - mScrollSpeed = mScrollProfile.getSpeed((mUpScrollStartYF - maxY) - / mDragUpScrollHeight, mPrevTime); - } else { - View v = getChildAt(last - first); - if (v == null) { - mScrolling = false; - return; - } else { - if (last == count - 1 && v.getBottom() <= listHeight + padTop) { - mScrolling = false; - return; - } - } - mScrollSpeed = -mScrollProfile.getSpeed((minY - mDownScrollStartYF) - / mDragDownScrollHeight, mPrevTime); - } - - mCurrTime = SystemClock.uptimeMillis(); - dt = (float) (mCurrTime - mPrevTime); - - // dy is change in View position of a list item; i.e. positive dy - // means user is scrolling up (list item moves down the screen, - // remember - // y=0 is at top of View). - dy = (int) Math.round(mScrollSpeed * dt); - - int movePos; - if (dy >= 0) { - dy = Math.min(listHeight, dy); - movePos = first; - } else { - dy = Math.max(-listHeight, dy); - movePos = last; - } - - final View moveItem = getChildAt(movePos - first); - int top = moveItem.getTop() + dy; - - if (movePos == 0 && top > padTop) { - top = padTop; - } - - // always do scroll - mBlockLayoutRequests = true; - - setSelectionFromTop(movePos, top - padTop); - DragSortListView.this.layoutChildren(); - invalidate(); - - mBlockLayoutRequests = false; - - // scroll means relative float View movement - doDragFloatView(movePos, moveItem, false); - - mPrevTime = mCurrTime; - - post(this); - } - } - - // TODO: Bluuurgh... switch to SharedPreferences - private class DragSortTracker { - StringBuilder mBuilder = new StringBuilder(); - - File mFile; - - private int mNumInBuffer = 0; - private int mNumFlushes = 0; - - private boolean mTracking = false; - - public DragSortTracker() { - File root = Environment.getExternalStorageDirectory(); - mFile = new File(root, "dslv_state.txt"); - - if (!mFile.exists()) { - try { - mFile.createNewFile(); - Log.d("mobeta", "file created"); - } catch (IOException e) { - Log.w("mobeta", "Could not create dslv_state.txt"); - Log.d("mobeta", e.getMessage()); - } - } - - } - - public void startTracking() { - mBuilder.append("\n"); - mNumFlushes = 0; - mTracking = true; - } - - public void appendState() { - if (!mTracking) { - return; - } - - mBuilder.append("\n"); - final int children = getChildCount(); - final int first = getFirstVisiblePosition(); - mBuilder.append(" "); - for (int i = 0; i < children; ++i) { - mBuilder.append(first + i).append(","); - } - mBuilder.append("\n"); - - mBuilder.append(" "); - for (int i = 0; i < children; ++i) { - mBuilder.append(getChildAt(i).getTop()).append(","); - } - mBuilder.append("\n"); - mBuilder.append(" "); - for (int i = 0; i < children; ++i) { - mBuilder.append(getChildAt(i).getBottom()).append(","); - } - mBuilder.append("\n"); - - mBuilder.append(" ").append(mFirstExpPos).append("\n"); - mBuilder.append(" ") - .append(getItemHeight(mFirstExpPos) - getChildHeight(mFirstExpPos)) - .append("\n"); - mBuilder.append(" ").append(mSecondExpPos).append("\n"); - mBuilder.append(" ") - .append(getItemHeight(mSecondExpPos) - getChildHeight(mSecondExpPos)) - .append("\n"); - mBuilder.append(" ").append(mSrcPos).append("\n"); - mBuilder.append(" ").append(mFloatViewHeight + getDividerHeight()) - .append("\n"); - mBuilder.append(" ").append(getHeight()).append("\n"); - mBuilder.append(" ").append(mLastY).append("\n"); - mBuilder.append(" ").append(mFloatViewMid).append("\n"); - mBuilder.append(" "); - for (int i = 0; i < children; ++i) { - mBuilder.append(getShuffleEdge(first + i, getChildAt(i).getTop())).append(","); - } - mBuilder.append("\n"); - - mBuilder.append("\n"); - mNumInBuffer++; - - if (mNumInBuffer > 1000) { - flush(); - mNumInBuffer = 0; - } - } - - public void flush() { - if (!mTracking) { - return; - } - - // save to file on sdcard - try { - boolean append = true; - if (mNumFlushes == 0) { - append = false; - } - FileWriter writer = new FileWriter(mFile, append); - - writer.write(mBuilder.toString()); - mBuilder.delete(0, mBuilder.length()); - - writer.flush(); - writer.close(); - - mNumFlushes++; - } catch (IOException e) { - // do nothing - } - } - - public void stopTracking() { - if (mTracking) { - mBuilder.append("\n"); - flush(); - mTracking = false; - } - } - - } - -} diff --git a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/ResourceDragSortCursorAdapter.java b/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/ResourceDragSortCursorAdapter.java deleted file mode 100644 index 32406ffb..00000000 --- a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/ResourceDragSortCursorAdapter.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mobeta.android.dslv; - -import android.content.Context; -import android.database.Cursor; -import android.support.v4.widget.CursorAdapter; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -// taken from v4 rev. 10 ResourceCursorAdapter.java - -/** - * Static library support version of the framework's {@link android.widget.ResourceCursorAdapter}. - * Used to write apps that run on platforms prior to Android 3.0. When running - * on Android 3.0 or above, this implementation is still used; it does not try - * to switch to the framework's implementation. See the framework SDK - * documentation for a class overview. - */ -public abstract class ResourceDragSortCursorAdapter extends DragSortCursorAdapter { - private int mLayout; - - private int mDropDownLayout; - - private LayoutInflater mInflater; - - /** - * Constructor the enables auto-requery. - * - * @param context The context where the ListView associated with this adapter is running - * @param layout resource identifier of a layout file that defines the views - * for this list item. Unless you override them later, this will - * define both the item views and the drop down views. - * @deprecated This option is discouraged, as it results in Cursor queries - * being performed on the application's UI thread and thus can cause poor - * responsiveness or even Application Not Responding errors. As an alternative, - * use {@link android.app.LoaderManager} with a {@link android.content.CursorLoader}. - */ - @Deprecated - public ResourceDragSortCursorAdapter(Context context, int layout, Cursor c) { - super(context, c); - mLayout = mDropDownLayout = layout; - mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - } - - /** - * Constructor with default behavior as per - * {@link CursorAdapter#CursorAdapter(Context, Cursor, boolean)}; it is recommended - * you not use this, but instead {@link #ResourceCursorAdapter(Context, int, Cursor, int)}. - * When using this constructor, {@link #FLAG_REGISTER_CONTENT_OBSERVER} - * will always be set. - * - * @param context The context where the ListView associated with this adapter is running - * @param layout resource identifier of a layout file that defines the views - * for this list item. Unless you override them later, this will - * define both the item views and the drop down views. - * @param c The cursor from which to get the data. - * @param autoRequery If true the adapter will call requery() on the - * cursor whenever it changes so the most recent - * data is always displayed. Using true here is discouraged. - */ - public ResourceDragSortCursorAdapter(Context context, int layout, Cursor c, - boolean autoRequery) { - - super(context, c, autoRequery); - mLayout = mDropDownLayout = layout; - mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - } - - /** - * Standard constructor. - * - * @param context The context where the ListView associated with this adapter is running - * @param layout Resource identifier of a layout file that defines the views - * for this list item. Unless you override them later, this will - * define both the item views and the drop down views. - * @param c The cursor from which to get the data. - * @param flags Flags used to determine the behavior of the adapter, - * as per {@link CursorAdapter#CursorAdapter(Context, Cursor, int)}. - */ - public ResourceDragSortCursorAdapter(Context context, int layout, Cursor c, int flags) { - super(context, c, flags); - mLayout = mDropDownLayout = layout; - mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - } - - /** - * Inflates view(s) from the specified XML file. - * - * @see android.widget.CursorAdapter#newView(android.content.Context, - * android.database.Cursor, ViewGroup) - */ - @Override - public View newView(Context context, Cursor cursor, ViewGroup parent) { - return mInflater.inflate(mLayout, parent, false); - } - - @Override - public View newDropDownView(Context context, Cursor cursor, ViewGroup parent) { - return mInflater.inflate(mDropDownLayout, parent, false); - } - - /** - *

Sets the layout resource of the item views.

- * - * @param layout the layout resources used to create item views - */ - public void setViewResource(int layout) { - mLayout = layout; - } - - /** - *

Sets the layout resource of the drop down views.

- * - * @param dropDownLayout the layout resources used to create drop down views - */ - public void setDropDownViewResource(int dropDownLayout) { - mDropDownLayout = dropDownLayout; - } -} diff --git a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/SimpleDragSortCursorAdapter.java b/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/SimpleDragSortCursorAdapter.java deleted file mode 100644 index 0a6d02a2..00000000 --- a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/SimpleDragSortCursorAdapter.java +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mobeta.android.dslv; - -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; -import android.support.v4.widget.CursorAdapter; -import android.support.v4.widget.SimpleCursorAdapter; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; - -// taken from sdk/sources/android-16/android/widget/SimpleCursorAdapter.java - -/** - * An easy adapter to map columns from a cursor to TextViews or ImageViews - * defined in an XML file. You can specify which columns you want, which - * views you want to display the columns, and the XML file that defines - * the appearance of these views. - *

- * Binding occurs in two phases. First, if a - * {@link android.widget.SimpleCursorAdapter.ViewBinder} is available, - * {@link ViewBinder#setViewValue(android.view.View, android.database.Cursor, int)} - * is invoked. If the returned value is true, binding has occured. If the - * returned value is false and the view to bind is a TextView, - * {@link #setViewText(TextView, String)} is invoked. If the returned value - * is false and the view to bind is an ImageView, - * {@link #setViewImage(ImageView, String)} is invoked. If no appropriate - * binding can be found, an {@link IllegalStateException} is thrown. - *

- * If this adapter is used with filtering, for instance in an - * {@link android.widget.AutoCompleteTextView}, you can use the - * {@link android.widget.SimpleCursorAdapter.CursorToStringConverter} and the - * {@link android.widget.FilterQueryProvider} interfaces - * to get control over the filtering process. You can refer to - * {@link #convertToString(android.database.Cursor)} and - * {@link #runQueryOnBackgroundThread(CharSequence)} for more information. - */ -public class SimpleDragSortCursorAdapter extends ResourceDragSortCursorAdapter { - /** - * A list of columns containing the data to bind to the UI. - * This field should be made private, so it is hidden from the SDK. - * {@hide} - */ - protected int[] mFrom; - /** - * A list of View ids representing the views to which the data must be bound. - * This field should be made private, so it is hidden from the SDK. - * {@hide} - */ - protected int[] mTo; - - private int mStringConversionColumn = -1; - private CursorToStringConverter mCursorToStringConverter; - private ViewBinder mViewBinder; - - String[] mOriginalFrom; - - /** - * Constructor the enables auto-requery. - * - * @deprecated This option is discouraged, as it results in Cursor queries - * being performed on the application's UI thread and thus can cause poor - * responsiveness or even Application Not Responding errors. As an alternative, - * use {@link android.app.LoaderManager} with a {@link android.content.CursorLoader}. - */ - @Deprecated - public SimpleDragSortCursorAdapter(Context context, int layout, Cursor c, String[] from, - int[] to) { - - super(context, layout, c); - mTo = to; - mOriginalFrom = from; - findColumns(c, from); - } - - /** - * Standard constructor. - * - * @param context The context where the ListView associated with this - * SimpleListItemFactory is running - * @param layout resource identifier of a layout file that defines the views - * for this list item. The layout file should include at least - * those named views defined in "to" - * @param c The database cursor. Can be null if the cursor is not available yet. - * @param from A list of column names representing the data to bind to the UI. Can be null - * if the cursor is not available yet. - * @param to The views that should display column in the "from" parameter. - * These should all be TextViews. The first N views in this list - * are given the values of the first N columns in the from - * parameter. Can be null if the cursor is not available yet. - * @param flags Flags used to determine the behavior of the adapter, - * as per {@link CursorAdapter#CursorAdapter(Context, Cursor, int)}. - */ - public SimpleDragSortCursorAdapter(Context context, int layout, Cursor c, String[] from, - int[] to, int flags) { - - super(context, layout, c, flags); - mTo = to; - mOriginalFrom = from; - findColumns(c, from); - } - - /** - * Binds all of the field names passed into the "to" parameter of the - * constructor with their corresponding cursor columns as specified in the - * "from" parameter. - *

- * Binding occurs in two phases. First, if a - * {@link android.widget.SimpleCursorAdapter.ViewBinder} is available, - * {@link ViewBinder#setViewValue(android.view.View, android.database.Cursor, int)} - * is invoked. If the returned value is true, binding has occured. If the - * returned value is false and the view to bind is a TextView, - * {@link #setViewText(TextView, String)} is invoked. If the returned value is - * false and the view to bind is an ImageView, - * {@link #setViewImage(ImageView, String)} is invoked. If no appropriate - * binding can be found, an {@link IllegalStateException} is thrown. - * - * @throws IllegalStateException if binding cannot occur - * @see android.widget.CursorAdapter#bindView(android.view.View, - * android.content.Context, android.database.Cursor) - * @see #getViewBinder() - * @see #setViewBinder(android.widget.SimpleCursorAdapter.ViewBinder) - * @see #setViewImage(ImageView, String) - * @see #setViewText(TextView, String) - */ - @Override - public void bindView(View view, Context context, Cursor cursor) { - final ViewBinder binder = mViewBinder; - final int count = mTo.length; - final int[] from = mFrom; - final int[] to = mTo; - - for (int i = 0; i < count; i++) { - final View v = view.findViewById(to[i]); - if (v != null) { - boolean bound = false; - if (binder != null) { - bound = binder.setViewValue(v, cursor, from[i]); - } - - if (!bound) { - String text = cursor.getString(from[i]); - if (text == null) { - text = ""; - } - - if (v instanceof TextView) { - setViewText((TextView) v, text); - } else if (v instanceof ImageView) { - setViewImage((ImageView) v, text); - } else { - throw new IllegalStateException(v.getClass().getName() + " is not a " + - " view that can be bounds by this SimpleCursorAdapter"); - } - } - } - } - } - - /** - * Returns the {@link ViewBinder} used to bind data to views. - * - * @return a ViewBinder or null if the binder does not exist - * @see #bindView(android.view.View, android.content.Context, android.database.Cursor) - * @see #setViewBinder(android.widget.SimpleCursorAdapter.ViewBinder) - */ - public ViewBinder getViewBinder() { - return mViewBinder; - } - - /** - * Sets the binder used to bind data to views. - * - * @param viewBinder the binder used to bind data to views, can be null to - * remove the existing binder - * @see #bindView(android.view.View, android.content.Context, android.database.Cursor) - * @see #getViewBinder() - */ - public void setViewBinder(ViewBinder viewBinder) { - mViewBinder = viewBinder; - } - - /** - * Called by bindView() to set the image for an ImageView but only if - * there is no existing ViewBinder or if the existing ViewBinder cannot - * handle binding to an ImageView. - *

- * By default, the value will be treated as an image resource. If the - * value cannot be used as an image resource, the value is used as an - * image Uri. - *

- * Intended to be overridden by Adapters that need to filter strings - * retrieved from the database. - * - * @param v ImageView to receive an image - * @param value the value retrieved from the cursor - */ - public void setViewImage(ImageView v, String value) { - try { - v.setImageResource(Integer.parseInt(value)); - } catch (NumberFormatException nfe) { - v.setImageURI(Uri.parse(value)); - } - } - - /** - * Called by bindView() to set the text for a TextView but only if - * there is no existing ViewBinder or if the existing ViewBinder cannot - * handle binding to a TextView. - *

- * Intended to be overridden by Adapters that need to filter strings - * retrieved from the database. - * - * @param v TextView to receive text - * @param text the text to be set for the TextView - */ - public void setViewText(TextView v, String text) { - v.setText(text); - } - - /** - * Return the index of the column used to get a String representation - * of the Cursor. - * - * @return a valid index in the current Cursor or -1 - * @see android.widget.CursorAdapter#convertToString(android.database.Cursor) - * @see #setStringConversionColumn(int) - * @see #setCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter) - * @see #getCursorToStringConverter() - */ - public int getStringConversionColumn() { - return mStringConversionColumn; - } - - /** - * Defines the index of the column in the Cursor used to get a String - * representation of that Cursor. The column is used to convert the - * Cursor to a String only when the current CursorToStringConverter - * is null. - * - * @param stringConversionColumn a valid index in the current Cursor or -1 to use the default - * conversion mechanism - * @see android.widget.CursorAdapter#convertToString(android.database.Cursor) - * @see #getStringConversionColumn() - * @see #setCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter) - * @see #getCursorToStringConverter() - */ - public void setStringConversionColumn(int stringConversionColumn) { - mStringConversionColumn = stringConversionColumn; - } - - /** - * Returns the converter used to convert the filtering Cursor - * into a String. - * - * @return null if the converter does not exist or an instance of - * {@link android.widget.SimpleCursorAdapter.CursorToStringConverter} - * @see #setCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter) - * @see #getStringConversionColumn() - * @see #setStringConversionColumn(int) - * @see android.widget.CursorAdapter#convertToString(android.database.Cursor) - */ - public CursorToStringConverter getCursorToStringConverter() { - return mCursorToStringConverter; - } - - /** - * Sets the converter used to convert the filtering Cursor - * into a String. - * - * @param cursorToStringConverter the Cursor to String converter, or - * null to remove the converter - * @see #setCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter) - * @see #getStringConversionColumn() - * @see #setStringConversionColumn(int) - * @see android.widget.CursorAdapter#convertToString(android.database.Cursor) - */ - public void setCursorToStringConverter(CursorToStringConverter cursorToStringConverter) { - mCursorToStringConverter = cursorToStringConverter; - } - - /** - * Returns a CharSequence representation of the specified Cursor as defined - * by the current CursorToStringConverter. If no CursorToStringConverter - * has been set, the String conversion column is used instead. If the - * conversion column is -1, the returned String is empty if the cursor - * is null or Cursor.toString(). - * - * @param cursor the Cursor to convert to a CharSequence - * @return a non-null CharSequence representing the cursor - */ - @Override - public CharSequence convertToString(Cursor cursor) { - if (mCursorToStringConverter != null) { - return mCursorToStringConverter.convertToString(cursor); - } else if (mStringConversionColumn > -1) { - return cursor.getString(mStringConversionColumn); - } - - return super.convertToString(cursor); - } - - /** - * Create a map from an array of strings to an array of column-id integers in cursor c. - * If c is null, the array will be discarded. - * - * @param c the cursor to find the columns from - * @param from the Strings naming the columns of interest - */ - private void findColumns(Cursor c, String[] from) { - if (c != null) { - int i; - int count = from.length; - if (mFrom == null || mFrom.length != count) { - mFrom = new int[count]; - } - for (i = 0; i < count; i++) { - mFrom[i] = c.getColumnIndexOrThrow(from[i]); - } - } else { - mFrom = null; - } - } - - @Override - public Cursor swapCursor(Cursor c) { - // super.swapCursor() will notify observers before we have - // a valid mapping, make sure we have a mapping before this - // happens - findColumns(c, mOriginalFrom); - return super.swapCursor(c); - } - - /** - * Change the cursor and change the column-to-view mappings at the same time. - * - * @param c The database cursor. Can be null if the cursor is not available yet. - * @param from A list of column names representing the data to bind to the UI. Can be null - * if the cursor is not available yet. - * @param to The views that should display column in the "from" parameter. - * These should all be TextViews. The first N views in this list - * are given the values of the first N columns in the from - * parameter. Can be null if the cursor is not available yet. - */ - public void changeCursorAndColumns(Cursor c, String[] from, int[] to) { - mOriginalFrom = from; - mTo = to; - // super.changeCursor() will notify observers before we have - // a valid mapping, make sure we have a mapping before this - // happens - findColumns(c, mOriginalFrom); - super.changeCursor(c); - } - - /** - * This class can be used by external clients of SimpleCursorAdapter - * to bind values fom the Cursor to views. - *

- * You should use this class to bind values from the Cursor to views - * that are not directly supported by SimpleCursorAdapter or to - * change the way binding occurs for views supported by - * SimpleCursorAdapter. - * - * @see SimpleCursorAdapter#bindView(android.view.View, android.content.Context, android.database.Cursor) - * @see SimpleCursorAdapter#setViewImage(ImageView, String) - * @see SimpleCursorAdapter#setViewText(TextView, String) - */ - public static interface ViewBinder { - /** - * Binds the Cursor column defined by the specified index to the specified view. - *

- * When binding is handled by this ViewBinder, this method must return true. - * If this method returns false, SimpleCursorAdapter will attempts to handle - * the binding on its own. - * - * @param view the view to bind the data to - * @param cursor the cursor to get the data from - * @param columnIndex the column at which the data can be found in the cursor - * @return true if the data was bound to the view, false otherwise - */ - boolean setViewValue(View view, Cursor cursor, int columnIndex); - } - - /** - * This class can be used by external clients of SimpleCursorAdapter - * to define how the Cursor should be converted to a String. - * - * @see android.widget.CursorAdapter#convertToString(android.database.Cursor) - */ - public static interface CursorToStringConverter { - /** - * Returns a CharSequence representing the specified Cursor. - * - * @param cursor the cursor for which a CharSequence representation - * is requested - * @return a non-null CharSequence representing the cursor - */ - CharSequence convertToString(Cursor cursor); - } - -} diff --git a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/SimpleFloatViewManager.java b/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/SimpleFloatViewManager.java deleted file mode 100644 index f101efd9..00000000 --- a/libraries/drag-sort-listview/library/src/com/mobeta/android/dslv/SimpleFloatViewManager.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.mobeta.android.dslv; - -import android.graphics.Bitmap; -import android.graphics.Color; -import android.graphics.Point; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.ListView; - -/** - * Simple implementation of the FloatViewManager class. Uses list - * items as they appear in the ListView to create the floating View. - */ -public class SimpleFloatViewManager implements DragSortListView.FloatViewManager { - - private Bitmap mFloatBitmap; - - private ImageView mImageView; - - private int mFloatBGColor = Color.BLACK; - - private ListView mListView; - - public SimpleFloatViewManager(ListView lv) { - mListView = lv; - } - - public void setBackgroundColor(int color) { - mFloatBGColor = color; - } - - /** - * This simple implementation creates a Bitmap copy of the - * list item currently shown at ListView position. - */ - @Override - public View onCreateFloatView(int position) { - // Guaranteed that this will not be null? I think so. Nope, got - // a NullPointerException once... - View v = mListView.getChildAt(position + mListView.getHeaderViewsCount() - - mListView.getFirstVisiblePosition()); - - if (v == null) { - return null; - } - - v.setPressed(false); - - // Create a copy of the drawing cache so that it does not get - // recycled by the framework when the list tries to clean up memory - v.setDrawingCacheEnabled(true); - mFloatBitmap = Bitmap.createBitmap(v.getDrawingCache()); - v.setDrawingCacheEnabled(false); - - if (mImageView == null) { - mImageView = new ImageView(mListView.getContext()); - } - mImageView.setBackgroundColor(mFloatBGColor); - mImageView.setPadding(0, 0, 0, 0); - mImageView.setImageBitmap(mFloatBitmap); - mImageView.setLayoutParams(new ViewGroup.LayoutParams(v.getWidth(), v.getHeight())); - - return mImageView; - } - - @Override - public void onDragFloatView(View floatView, Point position, Point touch) { - // Do nothing so we have a concrete class - } - - /** - * Removes the Bitmap from the ImageView created in - * onCreateFloatView() and tells the system to recycle it. - */ - @Override - public void onDestroyFloatView(View floatView) { - ((ImageView) floatView).setImageDrawable(null); - - mFloatBitmap.recycle(); - mFloatBitmap = null; - } - -} - diff --git a/libraries/drag-sort-listview/pom.xml b/libraries/drag-sort-listview/pom.xml deleted file mode 100644 index 9625aaba..00000000 --- a/libraries/drag-sort-listview/pom.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - 4.0.0 - - com.mobeta.android.dslv - parent - 0.6.2-SNAPSHOT - pom - - - UTF-8 - - 1.6 - 4.1.1.4 - r7 - - - - library - demo - - - - https://github.com/JayH5/drag-sort-listview/ - scm:git:git://github.com/JayH5/drag-sort-listview.git - scm:git:git@github.com:JayH5/drag-sort-listview.git - - - - - - - com.google.android - android - ${android.version} - - - - com.google.android - support-v4 - ${android.support-v4.version} - - - - - - - - org.apache.maven.plugins - maven-release-plugin - 2.5 - - true - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - ${java.version} - ${java.version} - - - - - com.jayway.maven.plugins.android.generation2 - android-maven-plugin - 3.8.2 - true - - - 19 - - - - - - - diff --git a/libraries/drag-sort-listview/settings.gradle b/libraries/drag-sort-listview/settings.gradle deleted file mode 100644 index 469ee85e..00000000 --- a/libraries/drag-sort-listview/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -include ':demo' -include ':library' diff --git a/libraries/drag-sort-listview/tools/demo-sign-align.sh b/libraries/drag-sort-listview/tools/demo-sign-align.sh deleted file mode 100755 index be5b9311..00000000 --- a/libraries/drag-sort-listview/tools/demo-sign-align.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -BINDIR="/Users/bauerca/db-workspace/drag-sort-listview/demo/bin" -KEYSTORE="/Users/bauerca/bauerca.keystore" -PROJ_NAME="DemoDSLV" -APK_US="${BINDIR}/${PROJ_NAME}-release-unsigned.apk" -APK="${BINDIR}/${PROJ_NAME}-release.apk" - -if [ -f $APK ] -then - rm $APK -fi - -jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore \ - $KEYSTORE $APK_US bauerca -zipalign -v 4 $APK_US $APK diff --git a/libraries/drag-sort-listview/tools/doc-dslv.sh b/libraries/drag-sort-listview/tools/doc-dslv.sh deleted file mode 100755 index 4adba7ca..00000000 --- a/libraries/drag-sort-listview/tools/doc-dslv.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -DOCLAVA_PATH=../../doclava-1.0.6/doclava-1.0.6.jar -AND_SDK=/Users/bauerca/Downloads/android-sdk-mac_86 -AND_SRC=${AND_SDK}/sources/android-16 -AND_API_XML=${AND_SRC}/current.xml - -javadoc \ - -sourcepath ${AND_SRC} -J-Xmx240m \ - -subpackages android.widget \ - -doclet com.google.doclava.Doclava \ - -docletpath ${DOCLAVA_PATH} \ - -nodocs -apixml ${AND_API_XML} - -javadoc \ - -doclet com.google.doclava.Doclava \ - -docletpath ${DOCLAVA_PATH} \ - -title DragSortListView \ - -federate Android http://developer.android.com/reference \ - -federationxml Android ${AND_API_XML} \ - com.mobeta.android.dslv diff --git a/libraries/drag-sort-listview/tools/dslv.py b/libraries/drag-sort-listview/tools/dslv.py deleted file mode 100644 index 3ab17814..00000000 --- a/libraries/drag-sort-listview/tools/dslv.py +++ /dev/null @@ -1,264 +0,0 @@ -from matplotlib.lines import Line2D -from matplotlib.text import Text -from matplotlib.patches import Rectangle -import pylab -from xml.etree.ElementTree import ElementTree - -width = 300 - -class ItemArtist: - - def __init__(self, position, state): - self.position = position - - indx = state.positions.index(position) - - self.top = -state.tops[indx] - self.top_line, = pylab.plot([0,width], 2*[self.top], c='b') - - self.bottom = -state.bottoms[indx] - self.bottom_line, = pylab.plot([0,width], 2*[self.bottom], c='b') - - self.edge = -state.edges[indx] - self.edge_line, = pylab.plot([0,width], 2*[self.edge], c='g') - - self.label = Text(width/2, (self.top+self.bottom)/2, - str(position), va='center', ha='center') - - self.axes = pylab.gca() - self.axes.add_artist(self.label) - - self.src_box = None - self.exp_box = None - self._check_boxes(state) - - - def _check_boxes(self, state): - - if self.position == state.src: - if self.src_box == None: - self.src_box = Rectangle((0, self.bottom), width, - self.top - self.bottom, fill=True, ec=None, fc='0.7') - self.axes.add_patch(self.src_box) - else: - self.src_box.set_y(self.bottom) - self.src_box.set_height(self.top - self.bottom) - - elif self.position == state.exp1: - if state.exp1 < state.src: - gap_bottom = self.top - state.exp1_gap - else: - gap_bottom = self.bottom - - if self.exp_box == None: - self.exp_box = Rectangle((0,gap_bottom), width, - state.exp1_gap, fill=True, ec=None, fc='0.7') - self.axes.add_patch(self.exp_box) - else: - self.exp_box.set_y(gap_bottom) - self.exp_box.set_height(state.exp1_gap) - - elif self.position == state.exp2: - if state.exp2 < state.src: - gap_bottom = self.top - state.exp2_gap - else: - gap_bottom = self.bottom - - if self.exp_box == None: - self.exp_box = Rectangle((0,gap_bottom), width, state.exp2_gap, - fill=True, ec=None, fc='0.7') - self.axes.add_patch(self.exp_box) - else: - self.exp_box.set_y(gap_bottom) - self.exp_box.set_height(state.exp2_gap) - else: - if self.src_box != None: - self.src_box.remove() - self.src_box = None - if self.exp_box != None: - self.exp_box.remove() - self.exp_box = None - - - def inState(self, state): - return self.position in state.positions - - def update(self, position, state): - moved = False - - if position != self.position: - self.position = position - self.label.set_text(str(position)) - - indx = state.positions.index(self.position) - - old_top = self.top - self.top = -state.tops[indx] - if old_top != self.top: - self.top_line.set_ydata(2*[self.top]) - moved = True - - old_bottom = self.bottom - self.bottom = -state.bottoms[indx] - if old_bottom != self.bottom: - self.bottom_line.set_ydata(2*[self.bottom]) - moved = True - - old_edge = self.edge - self.edge = -state.edges[indx] - if old_edge != self.edge: - self.edge_line.set_ydata(2*[self.edge]) - - if moved: - # adjust label, blank spot, etc. - self.label.set_y((self.top + self.bottom)/2) - self._check_boxes(state) - - def remove(self): - self.edge_line.remove() - self.top_line.remove() - self.bottom_line.remove() - self.label.remove() - - if self.src_box != None: - self.src_box.remove() - if self.exp_box != None: - self.exp_box.remove() - - -class StateArtist: - xbuff = 40 - ybuff = 100 - - def __init__(self, state): - - self.fig = pylab.figure(figsize=(5,9)) - self.axes = self.fig.add_subplot(111) - self.axes.set_aspect('equal') - - self.axes.set_ylim((-self.ybuff - state.height, self.ybuff)) - self.axes.set_xlim((-self.xbuff, width + self.xbuff)) - - self.float_y = -state.float_y - self.float_y_line, = pylab.plot([0,width], 2*[self.float_y], - c='r', lw=2) - - self.items = [] - self.update(state) - - self.axes.add_patch(Rectangle((0, -state.height), width, state.height, - fill=False, ls='dashed', ec='0.7')) - - def update(self, state): - - # update floatView location - old_float_y = self.float_y - self.float_y = -state.float_y - if old_float_y != self.float_y: - self.float_y_line.set_ydata(2*[self.float_y]) - - updatedPos = [] - toRecycle = [] - for item in self.items: - if item.inState(state): - item.update(item.position, state) - updatedPos.append(item.position) - else: - toRecycle.append(item) - - posSet = set(state.positions) - updatedPosSet = set(updatedPos) - - unupdatedPosSet = posSet.symmetric_difference(updatedPosSet) - for position in unupdatedPosSet: - if len(toRecycle) != 0: - item = toRecycle.pop(-1) - item.update(position, state) - else: - item = ItemArtist(position, state) - self.items.append(item) - - if len(toRecycle) != 0: - for item in toRecycle: - item.remove() #remove artists from current plot - self.items.remove(item) - - self.fig.canvas.draw() - -class State: - - def __init__(self, element): - self.positions = map(int, element.find("Positions").text.split(",")[:-1]) - self.tops = map(int, element.find("Tops").text.split(",")[:-1]) - self.bottoms = map(int, element.find("Bottoms").text.split(",")[:-1]) - self.count = len(self.positions) - self.edges = map(int, element.find("ShuffleEdges").text.split(",")[:-1]) - - self.src = int(element.find("SrcPos").text) - self.src_h = int(element.find("SrcHeight").text) - self.exp1 = int(element.find("FirstExpPos").text) - self.exp1_gap = int(element.find("FirstExpBlankHeight").text) - self.exp2 = int(element.find("SecondExpPos").text) - self.exp2_gap = int(element.find("SecondExpBlankHeight").text) - self.height = int(element.find("ViewHeight").text) - self.lasty = int(element.find("LastY").text) - self.float_y = int(element.find("FloatY").text) - - - -class StateAnimator: - page_frames = 30 - - def __init__(self, states, startFrame=0): - self.states = states - self.count = len(states) - - if startFrame < 0 or startFrame >= self.count: - self.curr = self.count - 1 - else: - self.curr = startFrame - - self.state_artist = StateArtist(self.states[self.curr]) - self.state_artist.fig.canvas.mpl_connect('key_press_event', self.flip) - - pylab.show() - - def flip(self, event): - #print event.key - if event.key == 'right': - self.curr += 1 - elif event.key == 'left': - self.curr -= 1 - elif event.key == 'up': - self.curr -= self.page_frames - elif event.key == 'down': - self.curr += self.page_frames - else: - return - - if self.curr >= self.count: - print "reached end of saved motions" - self.curr = self.count - 1 - elif self.curr < 0: - print "reached beginning of saved motions" - self.curr = 0 - else: - print "flipped to frame " + str(self.curr) - self.state_artist.update(self.states[self.curr]) - - - #self.ax.clear() - - - -def getStates(file): - tree = ElementTree(); - tree.parse(file); - root = tree.getroot() - - return map(State, list(root.iter("DSLVState"))) - - -if __name__ == "__main__": - states = getStates("dslv_state.txt") - StateAnimator(states, startFrame=-1) diff --git a/libraries/drag-sort-listview/tools/pkg-dslv.sh b/libraries/drag-sort-listview/tools/pkg-dslv.sh deleted file mode 100755 index 3e9c49e0..00000000 --- a/libraries/drag-sort-listview/tools/pkg-dslv.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -if [ ! $1 ] -then - echo "Need a version argument in the form of x.x.x" - exit 1 -fi - -base="drag-sort-listview" -dslvdir=$base-$1 - -if [ -d $dslvdir ] -then - rm -rf $dslvdir -fi - -git clone https://github.com/bauerca/drag-sort-listview.git $dslvdir -rm -rf "${dslvdir}/.git" - -tar -czf "${dslvdir}.tar.gz" $dslvdir -zip -r "${dslvdir}.zip" $dslvdir - -exit 0