- git (re)init (git structure was corrupted)

- added shuffler and repeat mode
- xxxhdpi icons
- typos
- new styles
- not fully working playing queue [alpha]
This commit is contained in:
Karim Abou Zeid 2015-01-25 01:05:25 +01:00
commit 32f76f5418
277 changed files with 20259 additions and 0 deletions

View file

@ -0,0 +1,20 @@
# 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

View file

@ -0,0 +1,50 @@
<?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>

View file

@ -0,0 +1,28 @@
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!

View file

@ -0,0 +1,34 @@
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')
}
}

View file

@ -0,0 +1,63 @@
<?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>

View file

@ -0,0 +1,20 @@
# 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 *;
#}

View file

@ -0,0 +1,15 @@
# 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 935 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -0,0 +1,6 @@
<?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"/>

View file

@ -0,0 +1,6 @@
<?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"/>

View file

@ -0,0 +1,10 @@
<?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>

View file

@ -0,0 +1,6 @@
<?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"/>

View file

@ -0,0 +1,10 @@
<?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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

View file

@ -0,0 +1,11 @@
<?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>

View file

@ -0,0 +1,7 @@
<?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"/>

View file

@ -0,0 +1,21 @@
<?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"/>

View file

@ -0,0 +1,20 @@
<?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"/>

View file

@ -0,0 +1,18 @@
<?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"/>

View file

@ -0,0 +1,8 @@
<?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"/>

View file

@ -0,0 +1,25 @@
<?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"/>

View file

@ -0,0 +1,30 @@
<?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>

View file

@ -0,0 +1,6 @@
<?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"/>

View file

@ -0,0 +1,19 @@
<?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>

View file

@ -0,0 +1,9 @@
<?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"/>

View file

@ -0,0 +1,28 @@
<?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>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="@dimen/item_height"
android:orientation="horizontal">
<ImageView
android:id="@id/drag_handle"
android:background="@drawable/drag"
android:layout_width="wrap_content"
android:layout_height="@dimen/item_height"
android:layout_weight="0"/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="@dimen/item_height"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center_vertical"
android:paddingLeft="8dp"/>
<ImageView
android:id="@id/click_remove"
android:background="@drawable/delete_x"
android:layout_width="@dimen/item_height"
android:layout_height="@dimen/item_height"
android:layout_weight="0"/>
</LinearLayout>

View file

@ -0,0 +1,21 @@
<?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>

View file

@ -0,0 +1,21 @@
<?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>

View file

@ -0,0 +1,6 @@
<?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"/>

View file

@ -0,0 +1,22 @@
<?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>

View file

@ -0,0 +1,6 @@
<?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"/>

View file

@ -0,0 +1,11 @@
<?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"/>

View file

@ -0,0 +1,6 @@
<?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 -->

View file

@ -0,0 +1,26 @@
<?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"/>

View file

@ -0,0 +1,13 @@
<?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>

View file

@ -0,0 +1,10 @@
<?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>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="item_height">67dp</dimen>
<dimen name="section_div_height">20dp</dimen>
</resources>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="drag_handle"/>
<item type="id" name="click_remove"/>
</resources>

View file

@ -0,0 +1,306 @@
<?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>

View file

@ -0,0 +1,114 @@
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;
}
}
}

View file

@ -0,0 +1,14 @@
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);
}
}

View file

@ -0,0 +1,38 @@
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();
}
}

View file

@ -0,0 +1,65 @@
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;
}
}
}

View file

@ -0,0 +1,184 @@
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);
}
}

View file

@ -0,0 +1,90 @@
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;
}
}
}
}

View file

@ -0,0 +1,50 @@
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;
}
});
}
}

View file

@ -0,0 +1,74 @@
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();
}
}

View file

@ -0,0 +1,72 @@
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();
}
}

View file

@ -0,0 +1,80 @@
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;
}
}
}

View file

@ -0,0 +1,65 @@
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();
}
}

View file

@ -0,0 +1,74 @@
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();
}
}

View file

@ -0,0 +1,259 @@
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;
}
}
}

View file

@ -0,0 +1,58 @@
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();
}
}

View file

@ -0,0 +1,128 @@
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);
}
}
}

View file

@ -0,0 +1,69 @@
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);
}
}