Commit 61d9f1f7 authored by Edward Wang's avatar Edward Wang

Add the sidebar

parent 1416c017
......@@ -10,3 +10,4 @@
# Project target.
target=android-15
android.library.reference.1=../java-libs/ActionBarSherlock
android.library.reference.2=../java-libs/SlidingMenu
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_height="match_parent"
android:divider="@color/item_common"
android:dividerHeight="1dp"
android:background="@android:color/black"
android:layout_width="208dp">
</ListView>
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
android:padding="13dip"
android:drawableLeft="@drawable/icon"
android:text="@string/title"
android:textColor="#ffffff"
android:textSize="20dip"
android:gravity="center" />
<?xml version="1.0" encoding="utf-8"?>
<com.slidingmenu.lib.SlidingMenu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sliding="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
sliding:behindScrollScale="0.5" />
......@@ -48,16 +48,22 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
......@@ -68,6 +74,7 @@ import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.slidingmenu.lib.SlidingMenu;
public class MainActivity extends SherlockFragmentActivity {
public final static String TAG = "VLC/MainActivity";
......@@ -81,6 +88,7 @@ public class MainActivity extends SherlockFragmentActivity {
private static final String PREF_SHOW_INFO = "show_info";
private ActionBar mActionBar;
private SlidingMenu mMenu;
private AudioMiniPlayer mAudioPlayer;
private AudioServiceController mAudioController;
private View mInfoLayout;
......@@ -110,7 +118,20 @@ public class MainActivity extends SherlockFragmentActivity {
if (Util.isICSOrLater()) /* Bug on pre-ICS, the progress bar is always present */
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
// Set up the sliding menu
setContentView(R.layout.sliding_menu);
mMenu = (SlidingMenu) findViewById(R.id.sliding_menu);
updateMenuOffset();
View v_main = LayoutInflater.from(this).inflate(R.layout.main, null);
mMenu.setViewAbove(v_main);
View sidebar = LayoutInflater.from(this).inflate(R.layout.sidebar, null);
((ListView)sidebar).setFooterDividersEnabled(true);
final ListView listView = (ListView)sidebar.findViewById(android.R.id.list);
listView.setAdapter(new SidebarAdapter());
listView.setBackgroundColor(Color.parseColor("#1f3f61"));
mMenu.setViewBehind(sidebar);
super.onCreate(savedInstanceState);
......@@ -119,9 +140,9 @@ public class MainActivity extends SherlockFragmentActivity {
LibVLC.useIOMX(this);
/* Initialize variables */
mInfoLayout = findViewById(R.id.info_layout);
mInfoProgress = (ProgressBar) findViewById(R.id.info_progress);
mInfoText = (TextView) findViewById(R.id.info_text);
mInfoLayout = v_main.findViewById(R.id.info_layout);
mInfoProgress = (ProgressBar) v_main.findViewById(R.id.info_progress);
mInfoText = (TextView) v_main.findViewById(R.id.info_text);
/* Initialize the tabs */
mActionBar = getSupportActionBar();
......@@ -188,6 +209,13 @@ public class MainActivity extends SherlockFragmentActivity {
MediaLibrary.getInstance(this).loadMediaItems(this);
}
private void updateMenuOffset() {
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int behindOffset_dp = Util.convertPxToDp(display.getWidth()) - 208;
mMenu.setBehindOffset(Util.convertDpToPx(behindOffset_dp));
}
@Override
protected void onResume() {
mAudioController.addAudioPlayer(mAudioPlayer);
......@@ -249,6 +277,12 @@ public class MainActivity extends SherlockFragmentActivity {
return super.onCreateOptionsMenu(menu);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updateMenuOffset();
}
@Override
public boolean onSearchRequested() {
Intent intent = new Intent(this, SearchActivity.class);
......
/*****************************************************************************
* SidebarAdapter.java
*****************************************************************************
* Copyright © 2012 VLC authors and VideoLAN
* Copyright © 2012 Edward Wang
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.gui;
import java.util.Arrays;
import java.util.List;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.VLCApplication;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class SidebarAdapter extends BaseAdapter {
public final static String TAG = "VLC/SidebarAdapter";
static class SidebarEntry {
String id;
String name;
int drawableID;
public SidebarEntry(String _id, String _name, int _drawableID) {
this.id = _id;
this.name = _name;
this.drawableID = _drawableID;
}
public SidebarEntry(String _id, int _name, int _drawableID) {
this.id = _id;
this.name = VLCApplication.getAppContext().getString(_name);
this.drawableID = _drawableID;
}
}
private LayoutInflater mInflater;
static final List<SidebarEntry> entries;
static {
SidebarEntry entries2[] = {
new SidebarEntry( "audio", R.string.audio, R.drawable.header_icon_audio ),
new SidebarEntry( "video", R.string.video, R.drawable.header_icon_video ),
new SidebarEntry( "directories", R.string.directories, R.drawable.ic_folder ),
new SidebarEntry( "history", "History", R.drawable.ic_folder ),
new SidebarEntry( "bookmarks", "Bookmarks", R.drawable.ic_folder ),
new SidebarEntry( "playlists", "Playlists", R.drawable.icon ),
};
entries = Arrays.asList(entries2);
}
public SidebarAdapter() {
mInflater = LayoutInflater.from(VLCApplication.getAppContext());
}
@Override
public int getCount() {
return entries.size();
}
@Override
public Object getItem(int position) {
return entries.get(position);
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View v, ViewGroup parent) {
SidebarEntry sidebarEntry = entries.get(position);
/* If view not created */
if(v == null) {
v = mInflater.inflate(R.layout.sidebar_item, parent, false);
}
TextView textView = (TextView)v;
textView.setText(sidebarEntry.name);
Drawable img = VLCApplication.getAppContext().getResources().getDrawable(sidebarEntry.drawableID);
int dp_32 = Util.convertDpToPx(32);
img.setBounds(0, 0, dp_32, dp_32);
textView.setCompoundDrawables(img, null, null, null);
return v;
}
}
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