[Android] SideBar: set the current fragment item text in bold
Adrien Maglo
git at videolan.org
Mon Mar 10 17:15:51 CET 2014
vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Mon Mar 10 17:15:41 2014 +0100| [8e4f12aeff21eca6f11884d1adfc2884f84d4efb] | committer: Adrien Maglo
SideBar: set the current fragment item text in bold
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=8e4f12aeff21eca6f11884d1adfc2884f84d4efb
---
.../src/org/videolan/vlc/gui/SidebarAdapter.java | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
index e65f205..05881ce 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
@@ -31,6 +31,7 @@ import org.videolan.vlc.gui.audio.AudioBrowserFragment;
import org.videolan.vlc.gui.video.VideoGridFragment;
import android.content.Context;
+import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import android.util.Log;
@@ -64,6 +65,7 @@ public class SidebarAdapter extends BaseAdapter {
private LayoutInflater mInflater;
static final List<SidebarEntry> entries;
private HashMap<String, Fragment> mFragments;
+ private String mCurrentFragmentId;
static {
SidebarEntry entries2[] = {
@@ -113,11 +115,22 @@ public class SidebarAdapter extends BaseAdapter {
img.setBounds(0, 0, dp_32, dp_32);
textView.setCompoundDrawables(img, null, null, null);
}
+ // Set in bold the current item.
+ if (mCurrentFragmentId.equals(sidebarEntry.id))
+ textView.setTypeface(null, Typeface.BOLD);
+ else
+ textView.setTypeface(null, Typeface.NORMAL);
return v;
}
public Fragment fetchFragment(String id) {
+ // Save the previous fragment in case an error happens after.
+ String prevFragmentId = mCurrentFragmentId;
+
+ // Set the current fragment.
+ setCurrentFragment(id);
+
if(mFragments.containsKey(id) && mFragments.get(id) != null) {
return mFragments.get(id);
}
@@ -132,6 +145,7 @@ public class SidebarAdapter extends BaseAdapter {
f = new HistoryFragment();
}
else {
+ mCurrentFragmentId = prevFragmentId; // Restore the current fragment id.
throw new IllegalArgumentException("Wrong fragment id.");
}
f.setRetainInstance(true);
@@ -139,6 +153,11 @@ public class SidebarAdapter extends BaseAdapter {
return f;
}
+ private void setCurrentFragment(String id) {
+ mCurrentFragmentId = id;
+ this.notifyDataSetChanged();
+ }
+
/**
* When Android has automatically recreated a fragment from the bundle state,
* use this function to 'restore' the recreated fragment into this sidebar
More information about the Android
mailing list