[Android] [PATCH] move openMRL and preferences buttons to sidebar
Geoffrey Métais
geoffrey.metais at gmail.com
Thu Nov 20 18:56:57 CET 2014
---
vlc-android/res/menu-v10/media_library.xml | 10 -----
vlc-android/res/menu-v13/media_library.xml | 10 -----
vlc-android/res/menu-v7/media_library.xml | 10 -----
vlc-android/res/values/attrs.xml | 2 +
vlc-android/res/values/styles.xml | 4 ++
.../src/org/videolan/vlc/gui/MainActivity.java | 52 ++++++++++++----------
.../src/org/videolan/vlc/gui/SidebarAdapter.java | 39 +++++++++-------
7 files changed, 58 insertions(+), 69 deletions(-)
diff --git a/vlc-android/res/menu-v10/media_library.xml b/vlc-android/res/menu-v10/media_library.xml
index 9e629ed..4117d25 100644
--- a/vlc-android/res/menu-v10/media_library.xml
+++ b/vlc-android/res/menu-v10/media_library.xml
@@ -9,12 +9,6 @@
android:nextFocusDown="@id/ml_menu_search"
vlc:showAsAction="ifRoom" />
<item
- android:id="@+id/ml_menu_open_mrl"
- android:icon="@drawable/ic_menu_goto_wb"
- android:title="@string/open_mrl"
- android:nextFocusDown="@id/ml_menu_open_mrl"
- vlc:showAsAction="ifRoom" />
- <item
android:title="@string/sortby"
android:icon="@drawable/ic_menu_sortby_wb"
android:id="@+id/ml_menu_sortby">
@@ -44,10 +38,6 @@
android:icon="@drawable/ic_menu_equalizer_wb"
android:title="@string/equalizer" />
<item
- android:id="@+id/ml_menu_preferences"
- android:icon="@drawable/ic_menu_preferences_wb"
- android:title="@string/preferences" />
- <item
android:id="@+id/ml_menu_about"
android:icon="@drawable/ic_menu_info_wb"
android:title="@string/about" />
diff --git a/vlc-android/res/menu-v13/media_library.xml b/vlc-android/res/menu-v13/media_library.xml
index fab1fc5..170fea1 100644
--- a/vlc-android/res/menu-v13/media_library.xml
+++ b/vlc-android/res/menu-v13/media_library.xml
@@ -9,12 +9,6 @@
android:nextFocusDown="@id/ml_menu_search"
vlc:showAsAction="ifRoom" />
<item
- android:id="@+id/ml_menu_open_mrl"
- android:icon="@drawable/ic_menu_goto"
- android:title="@string/open_mrl"
- android:nextFocusDown="@id/ml_menu_open_mrl"
- vlc:showAsAction="ifRoom" />
- <item
android:title="@string/sortby"
android:icon="@drawable/ic_menu_sortby"
android:id="@+id/ml_menu_sortby">
@@ -44,10 +38,6 @@
android:icon="@drawable/ic_menu_equalizer"
android:title="@string/equalizer" />
<item
- android:id="@+id/ml_menu_preferences"
- android:icon="@drawable/ic_menu_preferences"
- android:title="@string/preferences" />
- <item
android:id="@+id/ml_menu_about"
android:icon="@drawable/ic_menu_info"
android:title="@string/about" />
diff --git a/vlc-android/res/menu-v7/media_library.xml b/vlc-android/res/menu-v7/media_library.xml
index 9e629ed..4117d25 100644
--- a/vlc-android/res/menu-v7/media_library.xml
+++ b/vlc-android/res/menu-v7/media_library.xml
@@ -9,12 +9,6 @@
android:nextFocusDown="@id/ml_menu_search"
vlc:showAsAction="ifRoom" />
<item
- android:id="@+id/ml_menu_open_mrl"
- android:icon="@drawable/ic_menu_goto_wb"
- android:title="@string/open_mrl"
- android:nextFocusDown="@id/ml_menu_open_mrl"
- vlc:showAsAction="ifRoom" />
- <item
android:title="@string/sortby"
android:icon="@drawable/ic_menu_sortby_wb"
android:id="@+id/ml_menu_sortby">
@@ -44,10 +38,6 @@
android:icon="@drawable/ic_menu_equalizer_wb"
android:title="@string/equalizer" />
<item
- android:id="@+id/ml_menu_preferences"
- android:icon="@drawable/ic_menu_preferences_wb"
- android:title="@string/preferences" />
- <item
android:id="@+id/ml_menu_about"
android:icon="@drawable/ic_menu_info_wb"
android:title="@string/about" />
diff --git a/vlc-android/res/values/attrs.xml b/vlc-android/res/values/attrs.xml
index 8438257..e4601db 100644
--- a/vlc-android/res/values/attrs.xml
+++ b/vlc-android/res/values/attrs.xml
@@ -48,6 +48,8 @@
<attr name="ic_menu_audio" format="reference" />
<attr name="ic_menu_folder" format="reference" />
<attr name="ic_menu_history" format="reference" />
+ <attr name="ic_menu_openmrl" format="reference" />
+ <attr name="ic_menu_preferences" format="reference" />
<attr name="ic_move_media" format="reference" />
<attr name="mini_player_top_shadow" format="reference" />
diff --git a/vlc-android/res/values/styles.xml b/vlc-android/res/values/styles.xml
index 503ff69..e82e267 100644
--- a/vlc-android/res/values/styles.xml
+++ b/vlc-android/res/values/styles.xml
@@ -67,6 +67,8 @@
<item name="ic_menu_audio">@drawable/ic_menu_audio</item>
<item name="ic_menu_folder">@drawable/ic_menu_folder</item>
<item name="ic_menu_history">@drawable/ic_menu_history</item>
+ <item name="ic_menu_openmrl">@drawable/ic_menu_goto_wb</item>
+ <item name="ic_menu_preferences">@drawable/ic_menu_preferences_wb</item>
<item name="ic_move_media">@drawable/ic_move_media</item>
<item name="advanced_options_style">@style/Theme.VLC.AdvancedOptionsLight</item>
@@ -132,6 +134,8 @@
<item name="ic_menu_audio">@drawable/ic_menu_audio_w</item>
<item name="ic_menu_folder">@drawable/ic_menu_folder_w</item>
<item name="ic_menu_history">@drawable/ic_menu_history_w</item>
+ <item name="ic_menu_openmrl">@drawable/ic_menu_goto_wb</item>
+ <item name="ic_menu_preferences">@drawable/ic_menu_preferences_wb</item>
<item name="ic_move_media">@drawable/ic_move_media_w</item>
<item name="advanced_options_style">@style/Theme.VLC.AdvancedOptionsBlack</item>
</style>
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 87d567b..657fd8b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -106,6 +106,7 @@ public class MainActivity extends ActionBarActivity {
private static final int ACTIVITY_RESULT_PREFERENCES = 1;
private static final int ACTIVITY_SHOW_INFOLAYOUT = 2;
+ private Context mContext;
private ActionBar mActionBar;
private SidebarAdapter mSidebarAdapter;
private AudioPlayer mAudioPlayer;
@@ -150,6 +151,7 @@ public class MainActivity extends ActionBarActivity {
return;
}
+ mContext = this;
/* Get the current version from package */
PackageInfo pinfo = null;
try {
@@ -254,34 +256,42 @@ public class MainActivity extends ActionBarActivity {
if(entry == null || entry.id == null)
return;
+ if (entry.type == SidebarEntry.TYPE_FRAGMENT) {
/*
* Clear any backstack before switching tabs. This avoids
* activating an old backstack, when a user hits the back button
* to quit
*/
- getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
+ getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
/* Slide down the audio player */
- slideDownAudioPlayer();
+ slideDownAudioPlayer();
/* Switch the fragment */
- FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- ft.replace(R.id.fragment_placeholder, getFragment(entry.id), entry.id);
- ft.commit();
- mCurrentFragment = entry.id;
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ ft.replace(R.id.fragment_placeholder, getFragment(entry.id), entry.id);
+ ft.commit();
+ supportInvalidateOptionsMenu();
+ mCurrentFragment = entry.id;
/*
* Set user visibility hints to work around weird Android
* behaviour of duplicate context menu events.
*/
- current.setUserVisibleHint(false);
- getFragment(mCurrentFragment).setUserVisibleHint(true);
- // HACK ALERT: Set underlying audio browser to be invisible too.
- if(current.getTag().equals("tracks"))
- getFragment("audio").setUserVisibleHint(false);
-
- if (mFocusedPrior != 0)
- findViewById(R.id.ml_menu_search).requestFocus();
+ current.setUserVisibleHint(false);
+ getFragment(mCurrentFragment).setUserVisibleHint(true);
+ // HACK ALERT: Set underlying audio browser to be invisible too.
+ if(current.getTag().equals("tracks"))
+ getFragment("audio").setUserVisibleHint(false);
+
+ if (mFocusedPrior != 0)
+ findViewById(R.id.ml_menu_search).requestFocus();
+ mRootContainer.closeDrawer(mListView);
+ } else if (entry.attributeID == R.attr.ic_menu_openmrl){
+ onOpenMRL();
+ }else if (entry.attributeID == R.attr.ic_menu_preferences){
+ startActivityForResult(new Intent(mContext, PreferencesActivity.class), ACTIVITY_RESULT_PREFERENCES);
+ }
mRootContainer.closeDrawer(mListView);
}
});
@@ -594,7 +604,10 @@ public class MainActivity extends ActionBarActivity {
// Enable the clear search history function for the search fragment.
if (mCurrentFragment != null && mCurrentFragment.equals("search"))
menu.findItem(R.id.search_clear_history).setVisible(true);
- return true;
+
+ menu.findItem(R.id.ml_menu_last_playlist).setVisible(SidebarEntry.ID_AUDIO.equals(mCurrentFragment));
+
+ return super.onPrepareOptionsMenu(menu);
}
@Override
@@ -637,11 +650,6 @@ public class MainActivity extends ActionBarActivity {
case R.id.ml_menu_about:
showSecondaryFragment("about");
break;
- // Preferences
- case R.id.ml_menu_preferences:
- intent = new Intent(this, PreferencesActivity.class);
- startActivityForResult(intent, ACTIVITY_RESULT_PREFERENCES);
- break;
case R.id.ml_menu_equalizer:
showSecondaryFragment("equalizer");
break;
@@ -657,10 +665,6 @@ public class MainActivity extends ActionBarActivity {
Intent i = new Intent(AudioService.ACTION_REMOTE_LAST_PLAYLIST);
sendBroadcast(i);
break;
- // Open MRL
- case R.id.ml_menu_open_mrl:
- onOpenMRL();
- break;
case R.id.ml_menu_search:
onSearchRequested();
break;
diff --git a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
index 0e4f2b2..db50162 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
@@ -46,14 +46,26 @@ public class SidebarAdapter extends BaseAdapter {
public final static String TAG = "VLC/SidebarAdapter";
static class SidebarEntry {
+ public static final int TYPE_FRAGMENT = 0;
+ public static final int TYPE_ACTION = 1;
+
+ public static final String ID_VIDEO = "video";
+ public static final String ID_AUDIO = "audio";
+ public static final String ID_DIRECTORIES = "directories";
+ public static final String ID_HISTORY = "history";
+ public static final String ID_MRL = "mrl";
+ public static final String ID_PREFERENCES = "preferences";
+
String id;
String name;
int attributeID;
+ int type;
- public SidebarEntry(String _id, int _name, int _attributeID) {
- this.id = _id;
- this.name = VLCApplication.getAppContext().getString(_name);
- this.attributeID = _attributeID;
+ public SidebarEntry(String id, int name, int attributeID, int type) {
+ this.id = id;
+ this.name = VLCApplication.getAppContext().getString(name);
+ this.attributeID = attributeID;
+ this.type = type;
}
}
@@ -65,20 +77,17 @@ public class SidebarAdapter extends BaseAdapter {
private String mCurrentFragmentId;
static {
- SidebarEntry entries2[] = {
- new SidebarEntry( "video", R.string.video, R.attr.ic_menu_video ),
- new SidebarEntry( "audio", R.string.audio, R.attr.ic_menu_audio ),
- new SidebarEntry( "directories", R.string.directories, R.attr.ic_menu_folder ),
- new SidebarEntry( "history", R.string.history, R.attr.ic_menu_history ),
- //new SidebarEntry( "bookmarks", R.string.bookmarks, R.drawable.ic_bookmarks ),
- //new SidebarEntry( "playlists", R.string.playlists, R.drawable.icon ),
- };
- entries = Arrays.asList(entries2);
-
+ entries = new ArrayList<SidebarEntry>();
+ entries.add(new SidebarEntry(SidebarEntry.ID_VIDEO, R.string.video, R.attr.ic_menu_video, SidebarEntry.TYPE_FRAGMENT));
+ entries.add(new SidebarEntry(SidebarEntry.ID_AUDIO, R.string.audio, R.attr.ic_menu_audio, SidebarEntry.TYPE_FRAGMENT));
+ entries.add(new SidebarEntry(SidebarEntry.ID_DIRECTORIES, R.string.directories, R.attr.ic_menu_folder, SidebarEntry.TYPE_FRAGMENT));
+ entries.add(new SidebarEntry(SidebarEntry.ID_HISTORY, R.string.history, R.attr.ic_menu_history, SidebarEntry.TYPE_FRAGMENT));
sidebarFragments = new ArrayList<String>();
- for(SidebarEntry e : entries2) {
+ for(SidebarEntry e : entries) {
sidebarFragments.add(e.id);
}
+ entries.add(new SidebarEntry(SidebarEntry.ID_MRL, R.string.open_mrl, R.attr.ic_menu_openmrl, SidebarEntry.TYPE_ACTION));
+ entries.add(new SidebarEntry(SidebarEntry.ID_PREFERENCES, R.string.preferences, R.attr.ic_menu_preferences, SidebarEntry.TYPE_ACTION));
}
public SidebarAdapter(Context context) {
--
1.9.1
More information about the Android
mailing list