[Android] Enhance keyboard navigation
Geoffrey Métais
git at videolan.org
Thu Mar 5 17:22:20 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar 5 16:44:09 2015 +0100| [b49a9966bb0f4020ef700f2d8de2dc4a22613ca3] | committer: Geoffrey Métais
Enhance keyboard navigation
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=b49a9966bb0f4020ef700f2d8de2dc4a22613ca3
---
vlc-android/res/layout/sidebar.xml | 12 +++++++++---
.../src/org/videolan/vlc/gui/DirectoryViewFragment.java | 1 +
vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java | 6 ++++++
vlc-android/src/org/videolan/vlc/gui/MRLAdapter.java | 4 ++++
vlc-android/src/org/videolan/vlc/gui/MRLPanelFragment.java | 9 +++++++++
.../org/videolan/vlc/gui/audio/AudioBrowserFragment.java | 10 ++++------
.../src/org/videolan/vlc/gui/network/NetworkFragment.java | 10 ++++++++++
.../src/org/videolan/vlc/gui/video/VideoGridFragment.java | 4 +++-
8 files changed, 46 insertions(+), 10 deletions(-)
diff --git a/vlc-android/res/layout/sidebar.xml b/vlc-android/res/layout/sidebar.xml
index 5fdd22f..1d3035f 100644
--- a/vlc-android/res/layout/sidebar.xml
+++ b/vlc-android/res/layout/sidebar.xml
@@ -14,7 +14,7 @@
android:layout_above="@+id/sidebar_separator_settings"
android:nextFocusForward="@id/sidelist"
android:nextFocusUp="@id/sidelist"
- android:nextFocusDown="@id/sidelist"
+ android:nextFocusDown="@+id/settings"
android:nextFocusLeft="@id/sidelist"
android:nextFocusRight="@id/sidelist" >
</ListView>
@@ -51,10 +51,13 @@
android:layout_marginBottom="10dp"
android:clickable="true"
android:onClick="onClick"
+ android:focusable="true"
android:text="@string/preferences"
android:textColor="?attr/list_menu"
android:textSize="16sp"
- android:fontFamily="sans-serif"/>
+ android:fontFamily="sans-serif"
+ android:nextFocusUp="@id/sidelist"
+ android:nextFocusDown="@+id/about"/>
<ImageView
android:id="@+id/about_icon"
@@ -80,10 +83,13 @@
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:clickable="true"
+ android:focusable="true"
android:onClick="onClick"
android:text="@string/about"
android:textColor="?attr/list_menu"
android:textSize="16sp"
- android:fontFamily="sans-serif"/>
+ android:fontFamily="sans-serif"
+ android:nextFocusUp="@id/settings"
+ android:nextFocusDown="@id/about"/>
</RelativeLayout>
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
index 054214f..e18d4ec 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
@@ -84,6 +84,7 @@ public class DirectoryViewFragment extends BrowserFragment implements IRefreshab
filter.addAction(Intent.ACTION_MEDIA_EJECT);
filter.addDataScheme("file");
getActivity().registerReceiver(messageReceiver, filter);
+ focusHelper(mDirectoryAdapter.isEmpty());
}
private void focusHelper(boolean idIsEmpty) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
index 1f6558c..e5d0592 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
@@ -101,6 +101,12 @@ public class HistoryFragment extends BrowserFragment implements IRefreshable, Sw
}
@Override
+ public void onResume() {
+ super.onResume();
+ focusHelper(mHistoryAdapter.isEmpty());
+ }
+
+ @Override
public void onDestroy() {
mHistoryAdapter.release();
super.onDestroy();
diff --git a/vlc-android/src/org/videolan/vlc/gui/MRLAdapter.java b/vlc-android/src/org/videolan/vlc/gui/MRLAdapter.java
index 2a94a07..80cf0c4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MRLAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MRLAdapter.java
@@ -87,4 +87,8 @@ public class MRLAdapter extends RecyclerView.Adapter<MRLAdapter.ViewHolder> {
public int getItemCount() {
return mDataset.size();
}
+
+ public boolean isEmpty(){
+ return getItemCount() == 0;
+ }
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/MRLPanelFragment.java b/vlc-android/src/org/videolan/vlc/gui/MRLPanelFragment.java
index 7ed603c..dba607f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MRLPanelFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MRLPanelFragment.java
@@ -72,6 +72,7 @@ public class MRLPanelFragment extends Fragment implements View.OnKeyListener, Te
public void onStart(){
super.onStart();
getActivity().supportInvalidateOptionsMenu();
+ focusHelper(mAdapter.isEmpty());
}
private void updateHistory() {
@@ -111,4 +112,12 @@ public class MRLPanelFragment extends Fragment implements View.OnKeyListener, Te
return false;
}
+
+ private void focusHelper(boolean idIsEmpty) {
+ View parent = View.inflate(getActivity(),
+ R.layout.directory_view, null);
+ MainActivity main = (MainActivity)getActivity();
+ main.setMenuFocusDown(idIsEmpty, R.id.mrl_list);
+ main.setSearchAsFocusDown(idIsEmpty, parent, R.id.mrl_list);
+ }
}
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 d86907b..6077f98 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -221,6 +221,8 @@ public class AudioBrowserFragment extends BrowserFragment implements SwipeRefres
else if (mGenresAdapter.isEmpty() || mArtistsAdapter.isEmpty() ||
mAlbumsAdapter.isEmpty() || mSongsAdapter.isEmpty())
updateLists();
+ else
+ focusHelper(false, mLists.get(mViewPager.getCurrentItem()).getId());
mMediaLibrary.addUpdateHandler(mHandler);
final ListView current = (ListView)mLists.get(mViewPager.getCurrentItem());
current.post(new Runnable() {
@@ -491,13 +493,9 @@ public class AudioBrowserFragment extends BrowserFragment implements SwipeRefres
mAdaptersToNotify.clear();
// Refresh the fast scroll data, since SectionIndexer doesn't respect notifyDataSetChanged
- int[] lists = {R.id.artists_list, R.id.albums_list, R.id.songs_list, R.id.genres_list};
if (getView() != null) {
- ListView l;
- for (int r : lists) {
- l = (ListView) getView().findViewById(r);
- l.setFastScrollEnabled(true);
- }
+ for (View v : mLists)
+ ((ListView)v).setFastScrollEnabled(true);
}
focusHelper(false, R.id.artists_list);
mHandler.removeMessages(MSG_LOADING);
diff --git a/vlc-android/src/org/videolan/vlc/gui/network/NetworkFragment.java b/vlc-android/src/org/videolan/vlc/gui/network/NetworkFragment.java
index 8c15e9e..4ee7cc9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/network/NetworkFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/network/NetworkFragment.java
@@ -46,6 +46,7 @@ import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.BrowserFragment;
import org.videolan.vlc.gui.DividerItemDecoration;
+import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.interfaces.IRefreshable;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Strings;
@@ -172,6 +173,7 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
mLayoutManager.scrollToPositionWithOffset(savedPosition, 0);
savedPosition = 0;
}
+ focusHelper(mAdapter.isEmpty());
}
@Override
@@ -317,4 +319,12 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
updateDisplay();
}
};
+
+ private void focusHelper(boolean idIsEmpty) {
+ View parent = View.inflate(getActivity(),
+ R.layout.directory_view, null);
+ MainActivity main = (MainActivity)getActivity();
+ main.setMenuFocusDown(idIsEmpty, R.id.network_list);
+ main.setSearchAsFocusDown(idIsEmpty, parent, R.id.network_list);
+ }
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 1e29ac5..9331fbb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -194,8 +194,10 @@ public class VideoGridFragment extends BrowserFragment implements ISortable, IVi
final boolean refresh = mVideoAdapter.isEmpty();
if (refresh)
updateList();
- else
+ else {
mViewNomedia.setVisibility(View.GONE);
+ focusHelper(false);
+ }
//Get & set times
HashMap<String, Long> times = MediaDatabase.getInstance().getVideoTimes(getActivity());
mVideoAdapter.setTimes(times);
More information about the Android
mailing list