[Android] Audio player: on dragging expand the item under the finger and highlight the moved item
Adrien Maglo
git at videolan.org
Thu Jan 23 21:34:44 CET 2014
vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Thu Jan 23 21:34:27 2014 +0100| [6781e3fafeaaa1024da633d6340dec1f951a0369] | committer: Adrien Maglo
Audio player: on dragging expand the item under the finger and highlight the moved item
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=6781e3fafeaaa1024da633d6340dec1f951a0369
---
vlc-android/res/layout/audio_playlist_item.xml | 21 ++++++++++
.../videolan/vlc/gui/audio/AudioPlaylistView.java | 40 ++++++++++++++++++--
2 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/vlc-android/res/layout/audio_playlist_item.xml b/vlc-android/res/layout/audio_playlist_item.xml
index a8e3dc4..f4b1d38 100644
--- a/vlc-android/res/layout/audio_playlist_item.xml
+++ b/vlc-android/res/layout/audio_playlist_item.xml
@@ -6,6 +6,27 @@
android:orientation="vertical" >
<LinearLayout
+ android:id="@+id/item_expansion"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:orientation="vertical"
+ android:visibility="gone" >
+
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="45dp" />
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:layout_gravity="center"
+ android:layout_marginLeft="10dp"
+ android:layout_marginRight="10dp"
+ android:background="?attr/playlist_item_footer" />
+ </LinearLayout>
+
+ <LinearLayout
android:id="@+id/layout_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistView.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistView.java
index b8b8131..0ea330d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistView.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistView.java
@@ -100,6 +100,7 @@ public class AudioPlaylistView extends ListView {
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
+ dragging();
break;
case MotionEvent.ACTION_UP:
dragDropped();
@@ -133,6 +134,15 @@ public class AudioPlaylistView extends ListView {
public void startDrag(int positionDragStart, String title, String artist) {
mPositionDragStart = positionDragStart;
if (mDragShadow != null) {
+ for (int i = 0; i < getChildCount(); i++) {
+ View child = getChildAt(i);
+ AudioListAdapter.ViewHolder holder = (AudioListAdapter.ViewHolder)child.getTag();
+ if (holder.position == positionDragStart) {
+ LinearLayout layout = (LinearLayout)child.findViewById(R.id.layout_item);
+ layout.setBackgroundResource(R.color.darkorange);
+ }
+ }
+
TextView titleView = (TextView)mDragShadow.findViewById(R.id.title);
TextView artistView = (TextView)mDragShadow.findViewById(R.id.artist);
LinearLayout layout = (LinearLayout)mDragShadow.findViewById(R.id.layout_item);
@@ -143,27 +153,51 @@ public class AudioPlaylistView extends ListView {
}
}
+ private void dragging() {
+ // Find the child view that is currently touched (perform a hit test)
+ Rect rect = new Rect();
+ for (int i = 0; i < getChildCount(); i++) {
+ View child = getChildAt(i);
+ LinearLayout expansion = (LinearLayout)child.findViewById(R.id.item_expansion);
+
+ child.getHitRect(rect);
+ if (rect.contains(getWidth() / 2, (int)mTouchY))
+ expansion.setVisibility(LinearLayout.VISIBLE);
+ else
+ expansion.setVisibility(LinearLayout.GONE);
+ }
+ }
+
public void dragDropped() {
mIsDragging = false;
// Find the child view that was touched (perform a hit test)
Rect rect = new Rect();
- int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
+ for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
+ LinearLayout expansion = (LinearLayout)child.findViewById(R.id.item_expansion);
+ LinearLayout layout = (LinearLayout)child.findViewById(R.id.layout_item);
+
child.getHitRect(rect);
if (rect.contains(getWidth() / 2, (int)mTouchY)) {
// Send back the performed change thanks to the listener.
AudioListAdapter.ViewHolder holder = (AudioListAdapter.ViewHolder)child.getTag();
if (mOnItemDraggedListener != null)
mOnItemDraggedListener.OnItemDradded(mPositionDragStart, holder.position);
- break;
}
+ expansion.setVisibility(LinearLayout.GONE);
+ layout.setBackgroundResource(0);
}
}
public void dragAborted() {
mIsDragging = false;
+
+ for (int i = 0; i < getChildCount(); i++) {
+ View child = getChildAt(i);
+ LinearLayout expansion = (LinearLayout)child.findViewById(R.id.item_expansion);
+ expansion.setVisibility(LinearLayout.GONE);
+ }
}
public interface OnItemDraggedListener {
More information about the Android
mailing list