Commit 76b0aba8 authored by Mik Amchislavsky's avatar Mik Amchislavsky Committed by Geoffrey Métais
Browse files

AudioBrowserFragment: focus related improvement


Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent 41043f41
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_selected="false">
<shape android:shape="rectangle">
<solid android:color="@color/darkgrey" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/orange" />
</shape>
</item>
<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="@color/darkorange" />
</shape>
</item>
<item android:state_focused="false" android:state_selected="false">
<shape android:shape="rectangle">
<solid android:color="@color/background_menu" />
</shape>
</item>
</selector>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#FFcccccc" />
</shape>
</item>
<item
android:bottom="0dp"
android:left="-7dp"
android:right="-7dp"
android:top="-7dp">
<shape android:shape="rectangle" >
<padding
android:bottom="15dp"
android:left="10dp"
android:right="10dp"
android:top="15dp" />
<stroke
android:width="6dp"
android:color="@color/darkorange" />
<solid android:color="#00000000" />
</shape>
</item>
</layer-list>
......@@ -4,6 +4,9 @@
<item android:drawable="@drawable/tab_unselected" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/tab_selected" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>
<!-- Focused state -->
<item android:drawable="@drawable/tab_focused" android:state_focused="true"/>
<!-- Pressed -->
<item android:drawable="@drawable/tab_pressed" android:state_pressed="true" android:state_selected="true"/>
<item android:drawable="@drawable/tab_pressed" android:state_pressed="true"/>
......
......@@ -34,7 +34,10 @@
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:paddingLeft="20dp"
android:paddingRight="20dp" />
android:paddingRight="20dp"
android:nextFocusDown="@id/albums"
android:nextFocusLeft="@id/albums"
android:nextFocusRight="@id/albums" />
<ListView
android:id="@+id/songs"
......@@ -44,9 +47,12 @@
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:paddingLeft="20dp"
android:paddingRight="20dp" />
android:paddingRight="20dp"
android:nextFocusDown="@id/songs"
android:nextFocusLeft="@id/songs"
android:nextFocusRight="@id/songs" />
</org.videolan.vlc.widget.FlingViewGroup>
</FrameLayout>
</LinearLayout>
</TabHost>
\ No newline at end of file
</TabHost>
......@@ -13,7 +13,11 @@
android:fadingEdge="none"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/background_header">
android:background="@drawable/background_header_item"
android:nextFocusUp="@+id/ml_menu_search"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/header"
android:nextFocusRight="@id/header" >
<LinearLayout
android:id="@+id/header_layout"
android:layout_width="wrap_content"
......@@ -97,7 +101,12 @@
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false" />
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/artists_list"
android:nextFocusRight="@+id/albums_list" />
<ListView
android:id="@+id/albums_list"
android:layout_width="fill_parent"
......@@ -106,7 +115,12 @@
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false" />
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/artists_list"
android:nextFocusRight="@+id/songs_list" />
<ListView
android:id="@+id/songs_list"
android:layout_width="fill_parent"
......@@ -115,7 +129,12 @@
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false" />
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/albums_list"
android:nextFocusRight="@+id/genres_list" />
<ListView
android:id="@+id/genres_list"
android:layout_width="fill_parent"
......@@ -124,6 +143,11 @@
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false" />
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/songs_list"
android:nextFocusRight="@+id/genres_list" />
</org.videolan.vlc.widget.FlingViewGroup>
</LinearLayout>
......@@ -64,6 +64,7 @@ import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.view.KeyEvent;
public class AudioBrowserFragment extends Fragment {
public final static String TAG = "VLC/AudioBrowserFragment";
......@@ -128,6 +129,7 @@ public class AudioBrowserFragment extends Fragment {
return true;
}
});
mHeader.setOnKeyListener(keyListener);
mEmptyView = v.findViewById(R.id.no_media);
......@@ -146,6 +148,11 @@ public class AudioBrowserFragment extends Fragment {
albumList.setOnItemClickListener(albumListListener);
genreList.setOnItemClickListener(genreListListener);
artistList.setOnKeyListener(keyListener);
albumList.setOnKeyListener(keyListener);
songsList.setOnKeyListener(keyListener);
genreList.setOnKeyListener(keyListener);
registerForContextMenu(songsList);
registerForContextMenu(artistList);
registerForContextMenu(albumList);
......@@ -170,6 +177,65 @@ public class AudioBrowserFragment extends Fragment {
mMediaLibrary.addUpdateHandler(mHandler);
}
// Focus support. Start.
View.OnKeyListener keyListener = new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
/* Qualify key action to prevent redundant event
* handling.
*
* ACTION_DOWN occurs before focus change and
* may be used to find if change originated from the
* header or if the header must be updated explicitely with
* a call to mHeader.scroll(...).
*/
if (event.getAction() == KeyEvent.ACTION_DOWN) {
int newPosition = mFlingViewPosition;
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (newPosition < (MODE_TOTAL - 1))
newPosition++;
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
if (newPosition > 0)
newPosition--;
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
mFlingViewPosition = 0xFF;
break;
default:
return false;
}
if (newPosition != mFlingViewPosition) {
int[] lists = { R.id.artists_list, R.id.albums_list,
R.id.songs_list, R.id.genres_list };
ListView vList = (ListView)v.getRootView().
findViewById(lists[newPosition]);
if (!mHeader.isFocused())
mHeader.scroll(newPosition / 3.f);
if (vList.getCount() == 0)
mHeader.setNextFocusDownId(R.id.header);
else
mHeader.setNextFocusDownId(lists[newPosition]);
mFlingViewGroup.scrollTo(newPosition);
// assigned in onSwitched following mHeader.scroll
mFlingViewPosition = newPosition;
}
}
// clean up with MainActivity
return false;
}
};
// Focus support. End.
OnItemClickListener songListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, View v, int p, long id) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment