[Android] Audio browser: implement the header bar of the design
Adrien Maglo
git at videolan.org
Fri Nov 15 21:53:10 CET 2013
vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Fri Nov 15 21:52:54 2013 +0100| [74b31235ad67a534391e6066c1345a024ce91217] | committer: Adrien Maglo
Audio browser: implement the header bar of the design
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=74b31235ad67a534391e6066c1345a024ce91217
---
vlc-android/res/drawable/header_fadein_overlay.xml | 10 ++
.../res/drawable/header_fadeout_overlay.xml | 10 ++
vlc-android/res/layout/audio_browser.xml | 113 +++++++++++---------
.../vlc/gui/audio/AudioBrowserFragment.java | 21 +++-
4 files changed, 104 insertions(+), 50 deletions(-)
diff --git a/vlc-android/res/drawable/header_fadein_overlay.xml b/vlc-android/res/drawable/header_fadein_overlay.xml
new file mode 100644
index 0000000..e5ec0ff
--- /dev/null
+++ b/vlc-android/res/drawable/header_fadein_overlay.xml
@@ -0,0 +1,10 @@
+<?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:endColor="#00000000"
+ android:startColor="@color/background_menu_divider" />
+
+</shape>
\ No newline at end of file
diff --git a/vlc-android/res/drawable/header_fadeout_overlay.xml b/vlc-android/res/drawable/header_fadeout_overlay.xml
new file mode 100644
index 0000000..88eda8b
--- /dev/null
+++ b/vlc-android/res/drawable/header_fadeout_overlay.xml
@@ -0,0 +1,10 @@
+<?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:endColor="@color/background_menu_divider"
+ android:startColor="#00000000" />
+
+</shape>
\ No newline at end of file
diff --git a/vlc-android/res/layout/audio_browser.xml b/vlc-android/res/layout/audio_browser.xml
index d5cc0b4..969241f 100644
--- a/vlc-android/res/layout/audio_browser.xml
+++ b/vlc-android/res/layout/audio_browser.xml
@@ -4,56 +4,71 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
- <HorizontalScrollView
- android:id="@+id/header"
- android:scrollbars="none"
- android:fadingEdge="none"
+ <RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="?attr/background_menu">
- <LinearLayout
- android:id="@+id/header_layout"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:text="@string/artists"
- android:textSize="16sp"
- android:textColor="?attr/font_light"
- android:id="@+id/artists"
- android:layout_width="80sp"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal" />
- <TextView
- android:text="@string/albums"
- android:textSize="16sp"
- android:textColor="?attr/font_light"
- android:id="@+id/albums"
- android:layout_width="80sp"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal" />
- <TextView
- android:text="@string/songs"
- android:textSize="16sp"
- android:textColor="?attr/font_light"
- android:id="@+id/songs"
- android:layout_width="80sp"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal" />
- <TextView
- android:text="@string/genres"
- android:textSize="16sp"
- android:textColor="?attr/font_light"
- android:id="@+id/genres"
- android:layout_width="80sp"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal" />
- </LinearLayout>
- </HorizontalScrollView>
- <View
- android:layout_width="fill_parent"
- android:layout_height="1dip"
- android:background="?attr/background_menu_divider" />
+ android:layout_height="wrap_content" >
+ <HorizontalScrollView
+ android:id="@+id/header"
+ android:scrollbars="none"
+ android:fadingEdge="none"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:background="?attr/background_menu">
+ <LinearLayout
+ android:id="@+id/header_layout"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <TextView
+ android:text="@string/artists"
+ android:textSize="16sp"
+ android:textColor="?attr/font_light"
+ android:id="@+id/artists"
+ android:layout_width="80sp"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal" />
+ <TextView
+ android:text="@string/albums"
+ android:textSize="16sp"
+ android:textColor="?attr/font_light"
+ android:id="@+id/albums"
+ android:layout_width="80sp"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal" />
+ <TextView
+ android:text="@string/songs"
+ android:textSize="16sp"
+ android:textColor="?attr/font_light"
+ android:id="@+id/songs"
+ android:layout_width="80sp"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal" />
+ <TextView
+ android:text="@string/genres"
+ android:textSize="16sp"
+ android:textColor="?attr/font_light"
+ android:id="@+id/genres"
+ android:layout_width="80sp"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal" />
+ </LinearLayout>
+ </HorizontalScrollView>
+ <View
+ android:layout_width="20dip"
+ android:layout_height="10dip"
+ android:layout_alignBottom="@+id/header"
+ android:layout_alignLeft="@+id/header"
+ android:layout_alignTop="@+id/header"
+ android:background="@drawable/header_fadein_overlay" />
+ <View
+ android:layout_width="20dip"
+ android:layout_height="10dip"
+ android:layout_alignBottom="@+id/header"
+ android:layout_alignRight="@+id/header"
+ android:layout_alignTop="@+id/header"
+ android:background="@drawable/header_fadeout_overlay" />
+ </RelativeLayout>
<org.videolan.vlc.widget.FlingViewGroup
android:id="@+id/content"
android:layout_width="fill_parent"
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 6333ef0..5ddedd5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -51,6 +51,8 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
+import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
@@ -149,6 +151,23 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
registerForContextMenu(albumList);
registerForContextMenu(genreList);
+ v.getViewTreeObserver().addOnGlobalLayoutListener(
+ new ViewTreeObserver.OnGlobalLayoutListener() {
+ public void onGlobalLayout() {
+ LinearLayout hl = (LinearLayout)getView().findViewById(R.id.header_layout);
+ for (int i = 0; i < hl.getChildCount(); ++i) {
+ View t = (View)hl.getChildAt(i);
+ int width = getView().getWidth() / 2;
+ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, LayoutParams.WRAP_CONTENT, 1);
+ if (i == 0)
+ lp.setMargins(width / 2, 0, 0, 0);
+ else if (i == hl.getChildCount() - 1)
+ lp.setMargins(0, 0, width / 2, 0);
+ t.setLayoutParams(lp);
+ }
+ }
+ });
+
return v;
}
@@ -375,7 +394,7 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
if (hl == null)
return;
int width = hl.getChildAt(0).getWidth();
- int x = (int) (progress * width);
+ int x = (int) (progress * (MODE_TOTAL - 1) * width);
mHeader.smoothScrollTo(x, 0);
}
More information about the Android
mailing list