Clean Up
- replaced drag sort list view local lob with grade dependency - fixed absolute path to relative path
|
|
@ -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'
|
||||
}
|
||||
|
|
|
|||
36
libraries/drag-sort-listview/.gitignore
vendored
|
|
@ -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
|
||||
|
|
@ -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)`.
|
||||
|
|
@ -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 attr>`: (`<datatype>`, `<default value>`) `<description>`.
|
||||
|
||||
#### 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
|
||||
<dependency>
|
||||
<groupId>com.mobeta.android.dslv</groupId>
|
||||
<artifactId>drag-sort-listview</artifactId>
|
||||
<version>0.6.1-SNAPSHOT</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### 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.
|
||||
```
|
||||
|
||||
|
|
@ -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'
|
||||
}
|
||||
}
|
||||
20
libraries/drag-sort-listview/demo/.gitignore
vendored
|
|
@ -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
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mobeta.android.demodslv"
|
||||
android:versionCode="5"
|
||||
android:versionName="0.6.2">
|
||||
|
||||
<uses-sdk android:minSdkVersion="8"
|
||||
android:targetSdkVersion="21"/>
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@drawable/dslv_launcher">
|
||||
|
||||
<activity android:name="Launcher"
|
||||
android:icon="@drawable/dslv_launcher"
|
||||
android:label="@string/app_name">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity android:name="TestBedDSLV"
|
||||
android:label="Basic usage"/>
|
||||
|
||||
<activity android:name="ArbItemSizeDSLV"
|
||||
android:label="Arbitrary item heights"/>
|
||||
|
||||
<activity android:name="WarpDSLV"
|
||||
android:label="Warp"/>
|
||||
|
||||
<activity android:name="BGHandle"
|
||||
android:label="Background handle"/>
|
||||
|
||||
<activity android:name="Sections"
|
||||
android:label="Sections"/>
|
||||
|
||||
<activity android:name="CursorDSLV"
|
||||
android:label="Cursor-backed"/>
|
||||
|
||||
<activity android:name="MultipleChoiceListView"
|
||||
android:label="Multi-select list"/>
|
||||
|
||||
<activity android:name="SingleChoiceListView"
|
||||
android:label="Single-choice list"/>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
@ -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:<br/>
|
||||
• Drag initiation: on touch, on drag, on long-press<br/>
|
||||
• Item removal: on click, on fling, on slide<br/>
|
||||
|
||||
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!
|
||||
|
|
@ -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/<type>
|
||||
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
|
||||
// This moves them out of them default location under src/<type>/... 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')
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2012 Andreas Schildbach
|
||||
|
||||
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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.mobeta.android.dslv</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>0.6.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>com.mobeta.android.demodslv</groupId>
|
||||
<artifactId>drag-sort-listview-demo</artifactId>
|
||||
<packaging>apk</packaging>
|
||||
<version>0.6.2-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.mobeta.android.dslv</groupId>
|
||||
<artifactId>drag-sort-listview</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>android</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>support-v4</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<testSourceDirectory>test</testSourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
||||
<artifactId>android-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -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 *;
|
||||
#}
|
||||
|
|
@ -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
|
||||
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 935 B |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 640 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<clip
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@color/blue"
|
||||
android:clipOrientation="horizontal"
|
||||
android:gravity="left|fill_vertical"/>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<clip
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@color/blue"
|
||||
android:clipOrientation="horizontal"
|
||||
android:gravity="left|fill_vertical"/>
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:constantSize="true">
|
||||
<item
|
||||
android:drawable="@drawable/bg_handle_section1"
|
||||
android:state_pressed="false"/>
|
||||
<item
|
||||
android:drawable="@color/bg_handle_pressed"
|
||||
android:state_pressed="true"/>
|
||||
</selector>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<clip
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@color/darkblue"
|
||||
android:clipOrientation="horizontal"
|
||||
android:gravity="left|fill_vertical"/>
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:constantSize="true">
|
||||
<item
|
||||
android:drawable="@drawable/bg_handle_section2"
|
||||
android:state_pressed="false"/>
|
||||
<item
|
||||
android:drawable="@color/bg_handle_pressed"
|
||||
android:state_pressed="true"/>
|
||||
</selector>
|
||||
|
Before Width: | Height: | Size: 640 B |
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:angle="0"
|
||||
android:startColor="@color/grayStart"
|
||||
android:endColor="@color/grayEnd"
|
||||
android:type="linear"
|
||||
android:useLevel="false"/>
|
||||
</shape>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<fragment
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
class="com.mobeta.android.demodslv.DSLVFragmentBGHandle"
|
||||
android:id="@+id/bg_handle"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"/>
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mobeta.android.dslv.DragSortListView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dslv="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_margin="3dp"
|
||||
android:choiceMode="multipleChoice"
|
||||
android:dividerHeight="1px"
|
||||
android:padding="3dp"
|
||||
dslv:click_remove_id="@id/click_remove"
|
||||
dslv:collapsed_height="1px"
|
||||
dslv:drag_enabled="true"
|
||||
dslv:drag_handle_id="@id/drag_handle"
|
||||
dslv:drag_scroll_start="0.33"
|
||||
dslv:drag_start_mode="onDown"
|
||||
dslv:float_alpha="0.6"
|
||||
dslv:remove_enabled="true"
|
||||
dslv:remove_mode="clickRemove"
|
||||
dslv:slide_shuffle_speed="0.3"/>
|
||||
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mobeta.android.dslv.DragSortListView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dslv="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="3dp"
|
||||
android:layout_margin="3dp"
|
||||
android:dividerHeight="1px"
|
||||
dslv:drag_enabled="true"
|
||||
dslv:collapsed_height="1px"
|
||||
dslv:drag_scroll_start="0.33"
|
||||
dslv:float_alpha="0.6"
|
||||
dslv:slide_shuffle_speed="0.3"
|
||||
dslv:drag_start_mode="onDown"
|
||||
dslv:drag_handle_id="@id/drag_handle"
|
||||
dslv:remove_enabled="true"
|
||||
dslv:remove_mode="clickRemove"
|
||||
dslv:click_remove_id="@id/click_remove"/>
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mobeta.android.dslv.DragSortListView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dslv="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="3dp"
|
||||
android:layout_margin="3dp"
|
||||
android:dividerHeight="2dp"
|
||||
dslv:drag_enabled="true"
|
||||
dslv:collapsed_height="2dp"
|
||||
dslv:drag_scroll_start="0.33"
|
||||
dslv:max_drag_scroll_speed="0.5"
|
||||
dslv:float_alpha="0.6"
|
||||
dslv:slide_shuffle_speed="0.3"
|
||||
dslv:track_drag_sort="false"
|
||||
dslv:use_default_controller="false"/>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/text"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:gravity="center_vertical|center_horizontal"/>
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mobeta.android.dslv.DragSortListView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dslv="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:paddingTop="0dp"
|
||||
android:paddingBottom="0dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:layout_margin="10dp"
|
||||
android:dividerHeight="5dp"
|
||||
dslv:drag_enabled="true"
|
||||
dslv:collapsed_height="2dp"
|
||||
dslv:drag_scroll_start="0.33"
|
||||
dslv:max_drag_scroll_speed="0.5"
|
||||
dslv:float_alpha="0.6"
|
||||
dslv:slide_shuffle_speed="0.3"
|
||||
dslv:track_drag_sort="false"
|
||||
dslv:use_default_controller="true"
|
||||
dslv:drag_handle_id="@id/drag_handle"
|
||||
dslv:sort_enabled="true"
|
||||
dslv:remove_enabled="true"
|
||||
dslv:drag_start_mode="onDown"
|
||||
dslv:remove_mode="flingRemove"/>
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:paddingRight="5dp">
|
||||
<TextView
|
||||
android:id="@+id/artist_name_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"/>
|
||||
<TextView
|
||||
android:id="@+id/artist_albums_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@id/drag_handle"
|
||||
android:background="@drawable/drag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="0"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ListView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"/>
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/activity_title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:padding="4dp"/>
|
||||
<TextView
|
||||
android:id="@+id/activity_desc"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:padding="4dp"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="@drawable/bg_handle"
|
||||
android:id="@+id/text"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="24dp"/>
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mobeta.android.demodslv.CheckableLinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:id="@id/drag_handle"
|
||||
android:background="@drawable/drag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="0"/>
|
||||
<CheckedTextView
|
||||
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="8dp"/>
|
||||
<ImageView
|
||||
android:id="@id/click_remove"
|
||||
android:background="@drawable/delete_x"
|
||||
android:layout_width="@dimen/item_height"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="0"/>
|
||||
</com.mobeta.android.demodslv.CheckableLinearLayout>
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:id="@id/drag_handle"
|
||||
android:background="@drawable/drag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="0"/>
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="8dp"/>
|
||||
<ImageView
|
||||
android:id="@id/click_remove"
|
||||
android:background="@drawable/delete_x"
|
||||
android:layout_width="@dimen/item_height"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="0"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:id="@id/drag_handle"
|
||||
android:background="@drawable/drag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="0"/>
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="8dp"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="8dp"/>
|
||||
<ImageView
|
||||
android:id="@id/drag_handle"
|
||||
android:background="@drawable/drag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="0"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@id/drag_handle"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"/>
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mobeta.android.demodslv.CheckableLinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:id="@id/drag_handle"
|
||||
android:background="@drawable/drag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="0"/>
|
||||
<CheckedTextView
|
||||
android:checkMark="?android:attr/listChoiceIndicatorSingle"
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="8dp"/>
|
||||
</com.mobeta.android.demodslv.CheckableLinearLayout>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="@drawable/section_div"
|
||||
android:id="@+id/section_div"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/section_div_height"/>
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mobeta.android.dslv.DragSortListView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dslv="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:dividerHeight="1px"
|
||||
dslv:drag_enabled="true"
|
||||
dslv:float_alpha="0.6"
|
||||
dslv:use_default_controller="false"/>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/test_bed"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"/>
|
||||
<!-- We will add the DSLVFragment inside the FrameLayout in code -->
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mobeta.android.dslv.DragSortListView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dslv="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:paddingTop="0dp"
|
||||
android:paddingBottom="0dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:layout_margin="10dp"
|
||||
android:dividerHeight="5dp"
|
||||
android:fastScrollEnabled="true"
|
||||
dslv:drag_enabled="true"
|
||||
dslv:collapsed_height="2dp"
|
||||
dslv:drag_scroll_start="0.33"
|
||||
dslv:max_drag_scroll_speed="0.5"
|
||||
dslv:float_alpha="0.6"
|
||||
dslv:slide_shuffle_speed="0.3"
|
||||
dslv:track_drag_sort="false"
|
||||
dslv:use_default_controller="true"
|
||||
dslv:drag_handle_id="@id/drag_handle"
|
||||
dslv:sort_enabled="true"
|
||||
dslv:remove_enabled="true"
|
||||
dslv:drag_start_mode="onDown"
|
||||
dslv:remove_mode="flingRemove"/>
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/select_remove_mode"
|
||||
android:title="@string/select_remove_mode"/>
|
||||
<item android:id="@+id/select_drag_init_mode"
|
||||
android:title="@string/select_drag_init_mode"/>
|
||||
<item android:id="@+id/select_enables"
|
||||
android:title="@string/select_enables"/>
|
||||
<item android:id="@+id/add_header"
|
||||
android:title="@string/add_header"/>
|
||||
<item android:id="@+id/add_footer"
|
||||
android:title="@string/add_footer"/>
|
||||
</menu>
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="blue">#33b5e5</color>
|
||||
<color name="darkblue">#0099cc</color>
|
||||
<color name="red">#ff4444</color>
|
||||
<color name="grayStart">#adadad</color>
|
||||
<color name="grayEnd">#ffffff</color>
|
||||
<color name="black">#000000</color>
|
||||
<color name="bg_handle_pressed">#a0a0a0</color>
|
||||
</resources>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="item_height">67dp</dimen>
|
||||
<dimen name="section_div_height">20dp</dimen>
|
||||
</resources>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item type="id" name="drag_handle"/>
|
||||
<item type="id" name="click_remove"/>
|
||||
</resources>
|
||||
|
|
@ -1,306 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Drag-Sort Demos</string>
|
||||
<string-array name="activity_titles">
|
||||
<item>Basic usage playground</item>
|
||||
<item>Heteroheight</item>
|
||||
<item>Warp</item>
|
||||
<item>Background handle</item>
|
||||
<item>Sections</item>
|
||||
<item>CursorAdapter</item>
|
||||
<item>Multiple-choice mode</item>
|
||||
<item>Single-choice mode</item>
|
||||
</string-array>
|
||||
<string-array name="activity_descs">
|
||||
<item>
|
||||
Use the menu to adjust settings related to item
|
||||
removal and drag initiation. These options are
|
||||
provided by the DragSortController class.
|
||||
</item>
|
||||
<item>
|
||||
Demonstrates (tests) drag-sorting when list items
|
||||
have varying heights.
|
||||
</item>
|
||||
<item>
|
||||
Demonstrates drag-scroll customization; long lists
|
||||
need fast scrolling.
|
||||
</item>
|
||||
<item>
|
||||
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.
|
||||
</item>
|
||||
<item>
|
||||
Demonstrates floating View control from a custom
|
||||
FloatViewManager. Restrict item drags to list sections.
|
||||
</item>
|
||||
<item>
|
||||
Demonstrates usage of the DragSortCursorAdapter class,
|
||||
which abstracts drag-sorts with a remapping of Cursor
|
||||
positions to ListView positions.
|
||||
</item>
|
||||
<item>
|
||||
Uses Checkable list items in multiple-choice mode.
|
||||
</item>
|
||||
<item>
|
||||
Uses Checkable list items to allow for selectable radio
|
||||
buttons in single-choice mode.
|
||||
</item>
|
||||
</string-array>
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="select_remove_mode">Remove modes</string>
|
||||
<string name="select_drag_init_mode">Start-drag modes</string>
|
||||
<string name="select_enables">Enable/Disable</string>
|
||||
<string name="add_header">Add header</string>
|
||||
<string name="add_footer">Add footer</string>
|
||||
<string-array name="remove_mode_labels">
|
||||
<item>Click remove</item>
|
||||
<item>Fling remove</item>
|
||||
</string-array>
|
||||
<string-array name="drag_init_mode_labels">
|
||||
<item>On down</item>
|
||||
<item>On drag</item>
|
||||
<item>On long press</item>
|
||||
</string-array>
|
||||
<string-array name="enables_labels">
|
||||
<item>Enable drag</item>
|
||||
<item>Enable sort</item>
|
||||
<item>Enable remove</item>
|
||||
</string-array>
|
||||
<string-array name="jazz_artist_names">
|
||||
<item>Brad Mehldau</item>
|
||||
<item>Joshua Redman</item>
|
||||
<item>Chick Corea</item>
|
||||
<item>Kurt Rosenwinkel</item>
|
||||
<item>Miles Davis</item>
|
||||
<item>Wayne Shorter</item>
|
||||
<item>Michael Brecker</item>
|
||||
<item>Herbie Hancock</item>
|
||||
<item>Joe Zawinul</item>
|
||||
<item>Brian Blade</item>
|
||||
<item>Jeff Ballard</item>
|
||||
<item>Larry Grenadier</item>
|
||||
<item>Keith Jarrett</item>
|
||||
<item>McCoy Tyner</item>
|
||||
<item>Stephon Harris</item>
|
||||
<item>Mark Turner</item>
|
||||
</string-array>
|
||||
<string-array name="jazz_artist_albums">
|
||||
<item>Largo, Art of the Trio 1-4, Highway Rider, Songs</item>
|
||||
<item>Elastic, Momentum, Mood Swing, Back East</item>
|
||||
<item>Light as a Feather, Akoustic Band, My Spanish Heart</item>
|
||||
<item>Deep Song, Heartcore, Our Secret World, Reflections, The Remedy: Live at the Village
|
||||
Vanguard, The Enemies of Energy, The Next Step
|
||||
</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="countries">
|
||||
<item>Afghanistan</item>
|
||||
<item>Albania</item>
|
||||
<item>Algeria</item>
|
||||
<item>American Samoa</item>
|
||||
<item>Andorra</item>
|
||||
<item>Angola</item>
|
||||
<item>Anguilla</item>
|
||||
<item>Antigua and Barbuda</item>
|
||||
<item>Argentina</item>
|
||||
<item>Armenia</item>
|
||||
<item>Australia</item>
|
||||
<item>Austria</item>
|
||||
<item>Azerbajan</item>
|
||||
<item>Bahamas</item>
|
||||
<item>Bahrain</item>
|
||||
<item>Bangladesh</item>
|
||||
<item>Barbados</item>
|
||||
<item>Belarus</item>
|
||||
<item>Belgium</item>
|
||||
<item>Belize</item>
|
||||
<item>Benin</item>
|
||||
<item>Bermuda</item>
|
||||
<item>Bhutan</item>
|
||||
<item>Bolivia</item>
|
||||
<item>Bosnia and Herzegovina</item>
|
||||
<item>Botswana</item>
|
||||
<item>Brazil</item>
|
||||
<item>Brunei Darussalam</item>
|
||||
<item>Bulgaria</item>
|
||||
<item>Burkina Faso</item>
|
||||
<item>Burundi</item>
|
||||
<item>Cambodia</item>
|
||||
<item>Cameroon</item>
|
||||
<item>Canada</item>
|
||||
<item>Chile</item>
|
||||
<item>China</item>
|
||||
<item>Colombia</item>
|
||||
<item>Costa Rica</item>
|
||||
<item>Cuba</item>
|
||||
<item>Cyprus</item>
|
||||
<item>Czech Republic</item>
|
||||
<item>Democratic Republic Congo</item>
|
||||
<item>Denmark</item>
|
||||
<item>Djibouti</item>
|
||||
<item>Dominican Republic</item>
|
||||
<item>East Timor</item>
|
||||
<item>Ecuador</item>
|
||||
<item>Egypt</item>
|
||||
<item>El Salvador</item>
|
||||
<item>England</item>
|
||||
<item>Eritrea</item>
|
||||
<item>Estonia</item>
|
||||
<item>Ethiopia</item>
|
||||
<item>Faroe Islands</item>
|
||||
<item>Fiji</item>
|
||||
<item>Finland</item>
|
||||
<item>France</item>
|
||||
<item>French Polynesia</item>
|
||||
<item>Gambia</item>
|
||||
<item>Georgia (Sakartvelo)</item>
|
||||
<item>Germany</item>
|
||||
<item>Gabon</item>
|
||||
<item>Ghana</item>
|
||||
<item>Greece</item>
|
||||
<item>Greenland - Kalaallit Nunaat</item>
|
||||
<item>Grenada</item>
|
||||
<item>Gouadeloupe</item>
|
||||
<item>Guam</item>
|
||||
<item>Guatemala</item>
|
||||
<item>Guernsey</item>
|
||||
<item>Guyana</item>
|
||||
<item>Guyane</item>
|
||||
<item>Haiti</item>
|
||||
<item>Honduras</item>
|
||||
<item>Hong Kong</item>
|
||||
<item>Hrvatska (Croatia)</item>
|
||||
<item>Hungary</item>
|
||||
<item>Iceland</item>
|
||||
<item>India</item>
|
||||
<item>Indonesia</item>
|
||||
<item>Iran</item>
|
||||
<item>Iraq</item>
|
||||
<item>Ireland</item>
|
||||
<item>Israel</item>
|
||||
<item>Italy</item>
|
||||
<item>Jamaica</item>
|
||||
<item>Japan</item>
|
||||
<item>Jordan</item>
|
||||
<item>Kazakhstan</item>
|
||||
<item>Kenya</item>
|
||||
<item>Korea Republic</item>
|
||||
<item>Kosovo</item>
|
||||
<item>Kurdistan</item>
|
||||
<item>Kuwait</item>
|
||||
<item>Kyrgyzstan</item>
|
||||
<item>Laos</item>
|
||||
<item>Latvia</item>
|
||||
<item>Lebanon</item>
|
||||
<item>Lesotho</item>
|
||||
<item>Liberia</item>
|
||||
<item>Libyan Arab Jamahiriya</item>
|
||||
<item>Liechtenstein</item>
|
||||
<item>Lithuania</item>
|
||||
<item>Luxembourg</item>
|
||||
<item>Macau</item>
|
||||
<item>Macedonia</item>
|
||||
<item>Malawi</item>
|
||||
<item>Malaysia</item>
|
||||
<item>Mali</item>
|
||||
<item>Malta</item>
|
||||
<item>Marshall Islands</item>
|
||||
<item>Mauritania</item>
|
||||
<item>Martinique</item>
|
||||
<item>Mauritius</item>
|
||||
<item>Mexico</item>
|
||||
<item>Micronesia</item>
|
||||
<item>Moldova</item>
|
||||
<item>Monaco</item>
|
||||
<item>Mongolia</item>
|
||||
<item>Morocco</item>
|
||||
<item>Mozambique</item>
|
||||
<item>Namibia</item>
|
||||
<item>Nepal</item>
|
||||
<item>Netherlands</item>
|
||||
<item>Netherlands Antilles</item>
|
||||
<item>New Caledonia</item>
|
||||
<item>New Zealand (Aotearoa)</item>
|
||||
<item>Nicaragua</item>
|
||||
<item>Nigeria</item>
|
||||
<item>Niue</item>
|
||||
<item>Norfolk Island</item>
|
||||
<item>Northern Ireland</item>
|
||||
<item>Northern Mariana Islands</item>
|
||||
<item>Norway</item>
|
||||
<item>Oman</item>
|
||||
<item>Pakistan</item>
|
||||
<item>Palau</item>
|
||||
<item>Palestina</item>
|
||||
<item>Panama</item>
|
||||
<item>Papua New Guinea</item>
|
||||
<item>Paraguay</item>
|
||||
<item>Peru</item>
|
||||
<item>Philippines</item>
|
||||
<item>Portugal</item>
|
||||
<item>Puerto Rico</item>
|
||||
<item>Qatar</item>
|
||||
<item>Reunion</item>
|
||||
<item>Romania</item>
|
||||
<item>Russian Federation (AsianPart)</item>
|
||||
<item>Russian Federation (European Part)</item>
|
||||
<item>Rwanda</item>
|
||||
<item>Saint Kitts and Nevis</item>
|
||||
<item>Saint Vincent and the Grenadines</item>
|
||||
<item>Samoa (American Samoa)</item>
|
||||
<item>Samoa (Western Samoa)</item>
|
||||
<item>San Marino</item>
|
||||
<item>Saudi Arabia</item>
|
||||
<item>Scotland</item>
|
||||
<item>Senegal</item>
|
||||
<item>Seychelles</item>
|
||||
<item>Sierra Leone</item>
|
||||
<item>Singapore</item>
|
||||
<item>Slovakia</item>
|
||||
<item>Slovenia</item>
|
||||
<item>Solomon Islands</item>
|
||||
<item>Somalia</item>
|
||||
<item>Somaliland</item>
|
||||
<item>South Africa</item>
|
||||
<item>Spain</item>
|
||||
<item>Sri Lanka</item>
|
||||
<item>Sudan</item>
|
||||
<item>Suriname</item>
|
||||
<item>Svalbard and Jan Mayen</item>
|
||||
<item>Swaziland</item>
|
||||
<item>Sweden</item>
|
||||
<item>Switzerland</item>
|
||||
<item>Syrian Arab Republic</item>
|
||||
<item>Taiwan</item>
|
||||
<item>Tanzania</item>
|
||||
<item>Thailand</item>
|
||||
<item>Tibet</item>
|
||||
<item>Togo</item>
|
||||
<item>Tonga</item>
|
||||
<item>Trinidad and Tobago</item>
|
||||
<item>Tunisia</item>
|
||||
<item>Turkey</item>
|
||||
<item>Turkmenistan</item>
|
||||
<item>Turks and Caicos Islands</item>
|
||||
<item>Uganda</item>
|
||||
<item>Ukraine</item>
|
||||
<item>United Arab Emirates</item>
|
||||
<item>United Kingdom</item>
|
||||
<item>Uruguay</item>
|
||||
<item>USA</item>
|
||||
<item>Uzbekistan</item>
|
||||
<item>Vatican City State - Holy See</item>
|
||||
<item>Venezuela</item>
|
||||
<item>Viet Nam</item>
|
||||
<item>Virgin Islands (British)</item>
|
||||
<item>Virgin Islands (U.S.)</item>
|
||||
<item>Wales</item>
|
||||
<item>Yemen</item>
|
||||
<item>Yugoslavia</item>
|
||||
<item>Zambia</item>
|
||||
<item>Zimbabwe</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
@ -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<JazzArtist> artists = new ArrayList<JazzArtist>(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<JazzArtist> {
|
||||
|
||||
public JazzAdapter(List<JazzArtist> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String> 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<String> list = new ArrayList<String>(Arrays.asList(array));
|
||||
|
||||
mAdapter = new ArrayAdapter<String>(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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<String> list = new ArrayList<String>(Arrays.asList(array));
|
||||
setListAdapter(new MyAdapter(list));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DragSortController buildController(DragSortListView dslv) {
|
||||
return new MyDSController(dslv);
|
||||
}
|
||||
|
||||
|
||||
private class MyAdapter extends ArrayAdapter<String> {
|
||||
|
||||
public MyAdapter(List<String> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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<ActivityInfo> 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<ActivityInfo>(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<ActivityInfo> {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<String> 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<String> arrayList = new ArrayList<String>(Arrays.asList(array));
|
||||
|
||||
adapter = new ArrayAdapter<String>(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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String> list = new ArrayList<String>(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<String> mData;
|
||||
|
||||
private int mDivPos;
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public SectionAdapter(Context context, List<String> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String> 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<String> arrayList = new ArrayList<String>(Arrays.asList(array));
|
||||
|
||||
adapter = new ArrayAdapter<String>(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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String> 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<String> list = new ArrayList<String>(Arrays.asList(array));
|
||||
|
||||
mAdapter = new ArrayAdapter<String>(this, R.layout.list_item_handle_right, R.id.text, list);
|
||||
setListAdapter(mAdapter);
|
||||
}
|
||||
|
||||
}
|
||||
164
libraries/drag-sort-listview/gradlew
vendored
|
|
@ -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 "$@"
|
||||
90
libraries/drag-sort-listview/gradlew.bat
vendored
|
|
@ -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
|
||||
22
libraries/drag-sort-listview/library/.gitignore
vendored
|
|
@ -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
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mobeta.android.dslv"
|
||||
android:versionCode="5"
|
||||
android:versionName="0.6.2">
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
android:targetSdkVersion="21"/>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -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/<type>
|
||||
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
|
||||
// This moves them out of them default location under src/<type>/... 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')
|
||||
}
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2012 Andreas Schildbach
|
||||
|
||||
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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.mobeta.android.dslv</groupId>
|
||||
<artifactId>drag-sort-listview</artifactId>
|
||||
<packaging>apklib</packaging>
|
||||
<version>0.6.2-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.mobeta.android.dslv</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>0.6.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>android</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>support-v4</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<testSourceDirectory>test</testSourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
||||
<artifactId>android-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<configuration>
|
||||
<docletArtifact>
|
||||
<groupId>com.google.doclava</groupId>
|
||||
<artifactId>doclava</artifactId>
|
||||
<version>1.0.5</version>
|
||||
</docletArtifact>
|
||||
<doclet>com.google.doclava.Doclava</doclet>
|
||||
<!--
|
||||
| bootclasspath required by Sun's JVM
|
||||
-->
|
||||
<bootclasspath>${sun.boot.class.path}</bootclasspath>
|
||||
<additionalparam>
|
||||
-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
|
||||
</additionalparam>
|
||||
<useStandardDocletOptions>false</useStandardDocletOptions>
|
||||
<!--
|
||||
| Apple's JVM sometimes requires more memory
|
||||
-->
|
||||
<additionalJOption>-J-Xmx1024m</additionalJOption>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -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 *;
|
||||
#}
|
||||
|
|
@ -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
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<resources>
|
||||
<declare-styleable name="DragSortListView">
|
||||
<attr name="collapsed_height" format="dimension"/>
|
||||
|
||||
<!-- Float view -->
|
||||
<attr name="float_background_color" format="color"/>
|
||||
<attr name="float_alpha" format="float"/>
|
||||
|
||||
<!-- Animations -->
|
||||
<attr name="remove_animation_duration" format="integer"/>
|
||||
<attr name="drop_animation_duration" format="integer"/>
|
||||
<attr name="slide_shuffle_speed" format="float"/>
|
||||
|
||||
<!-- Remove properties -->
|
||||
<attr name="remove_enabled" format="boolean"/>
|
||||
<attr name="remove_mode">
|
||||
<enum name="clickRemove" value="0"/>
|
||||
<enum name="flingRemove" value="1"/>
|
||||
</attr>
|
||||
<attr name="fling_handle_id" format="integer"/>
|
||||
<attr name="click_remove_id" format="integer"/>
|
||||
|
||||
<!-- Drag properties -->
|
||||
<attr name="drag_enabled" format="boolean"/>
|
||||
<attr name="drag_start_mode">
|
||||
<enum name="onDown" value="0"/>
|
||||
<enum name="onMove" value="1"/>
|
||||
<enum name="onLongPress" value="2"/>
|
||||
</attr>
|
||||
<attr name="drag_handle_id" format="integer"/>
|
||||
<attr name="drag_scroll_start" format="float"/>
|
||||
<attr name="max_drag_scroll_speed" format="float"/>
|
||||
|
||||
<attr name="track_drag_sort" format="boolean"/>
|
||||
<attr name="use_default_controller" format="boolean"/>
|
||||
<attr name="sort_enabled" format="boolean"/>
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
|
@ -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.
|
||||
* <p/>
|
||||
* 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 <code>true</code> 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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -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.
|
||||
* <p/>
|
||||
* 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<Integer> mRemovedCursorPositions = new ArrayList<Integer>();
|
||||
|
||||
@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<Integer> toRemove = new ArrayList<Integer>();
|
||||
|
||||
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<Integer> getCursorPositions() {
|
||||
List<Integer> result = new ArrayList<Integer>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
* <p/>
|
||||
* <p/>
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
* <p/>
|
||||
* <p/>
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Sets the layout resource of the item views.</p>
|
||||
*
|
||||
* @param layout the layout resources used to create item views
|
||||
*/
|
||||
public void setViewResource(int layout) {
|
||||
mLayout = layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Sets the layout resource of the drop down views.</p>
|
||||
*
|
||||
* @param dropDownLayout the layout resources used to create drop down views
|
||||
*/
|
||||
public void setDropDownViewResource(int dropDownLayout) {
|
||||
mDropDownLayout = dropDownLayout;
|
||||
}
|
||||
}
|
||||
|
|
@ -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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <code>position</code>.
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,101 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2012 Andreas Schildbach
|
||||
|
||||
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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.mobeta.android.dslv</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>0.6.2-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<java.version>1.6</java.version>
|
||||
<android.version>4.1.1.4</android.version>
|
||||
<android.support-v4.version>r7</android.support-v4.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>library</module>
|
||||
<module>demo</module>
|
||||
</modules>
|
||||
|
||||
<scm>
|
||||
<url>https://github.com/JayH5/drag-sort-listview/</url>
|
||||
<connection>scm:git:git://github.com/JayH5/drag-sort-listview.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:JayH5/drag-sort-listview.git
|
||||
</developerConnection>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>android</artifactId>
|
||||
<version>${android.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>support-v4</artifactId>
|
||||
<version>${android.support-v4.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<configuration>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
||||
<artifactId>android-maven-plugin</artifactId>
|
||||
<version>3.8.2</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<sdk>
|
||||
<platform>19</platform>
|
||||
</sdk>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
include ':demo'
|
||||
include ':library'
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
@ -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
|
||||