Commit 9d425f9b authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Java code improvements and code cosmetics

parent e1705713
......@@ -30,8 +30,8 @@ import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.VLCCallbackTask;
import org.videolan.vlc.gui.audio.AudioBrowserFragment;
import org.videolan.vlc.gui.video.VideoListFragment;
import org.videolan.vlc.gui.video.VideoListAdapter;
import org.videolan.vlc.gui.video.VideoListFragment;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.interfaces.ISortable;
import org.videolan.vlc.widget.AudioMiniPlayer;
......@@ -51,7 +51,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
......@@ -106,33 +105,32 @@ public class MainActivity extends SherlockFragmentActivity {
LibVLC.useIOMX(this);
/* Initialize variables */
mInfoLayout = (View) findViewById(R.id.info_layout);
mInfoLayout = findViewById(R.id.info_layout);
mInfoProgress = (ProgressBar) findViewById(R.id.info_progress);
mInfoText = (TextView) findViewById(R.id.info_text);
/* Initialize the tabs */
mActionBar = getSupportActionBar();
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mActionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
mActionBar.addTab(mActionBar.newTab()
.setText("Video")
.setIcon(R.drawable.header_icon_video)
.setTabListener(new TabListener<VideoListFragment>(
this, "video", VideoListFragment.class)));
mActionBar.addTab(mActionBar.newTab()
.setText("Audio")
.setIcon(R.drawable.header_icon_audio)
.setTabListener(new TabListener<AudioBrowserFragment>(
this, "audio", AudioBrowserFragment.class)));
if (savedInstanceState != null) {
mActionBar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
}
// add mini audio player
// Add mini audio player
mAudioPlayer = (AudioMiniPlayer) findViewById(R.id.audio_mini_player);
mAudioController = AudioServiceController.getInstance();
mAudioPlayer.setAudioPlayerControl(mAudioController);
......@@ -261,6 +259,7 @@ public class MainActivity extends SherlockFragmentActivity {
b.setMessage(R.string.open_mrl_dialog_msg);
b.setView(input);
b.setPositiveButton("Open", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int button) {
ProgressDialog pd = ProgressDialog.show(
MainActivity.this,
......@@ -400,7 +399,7 @@ public class MainActivity extends SherlockFragmentActivity {
onSearchRequested();
}
private BroadcastReceiver messageReceiver = new BroadcastReceiver() {
private final BroadcastReceiver messageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
......@@ -449,12 +448,12 @@ public class MainActivity extends SherlockFragmentActivity {
context.getApplicationContext().sendBroadcast(intent);
}
public static class TabListener<T extends Fragment> implements ActionBar.TabListener {
private final SherlockFragmentActivity mActivity;
private final String mTag;
......@@ -483,12 +482,13 @@ public class MainActivity extends SherlockFragmentActivity {
}
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (mTag.equalsIgnoreCase("video"))
ft.setCustomAnimations(R.anim.anim_enter_left, R.anim.anim_leave_left);
else if (mTag.equalsIgnoreCase("audio"))
ft.setCustomAnimations(R.anim.anim_enter_right, R.anim.anim_leave_right);
if (mFragment == null) {
mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
ft.add(R.id.fragment_placeholder, mFragment, mTag);
......@@ -497,6 +497,7 @@ public class MainActivity extends SherlockFragmentActivity {
}
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mTag.equalsIgnoreCase("video"))
ft.setCustomAnimations(R.anim.anim_enter_left, R.anim.anim_leave_left);
......@@ -510,8 +511,9 @@ public class MainActivity extends SherlockFragmentActivity {
}
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
}
}
......@@ -46,6 +46,7 @@ import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentTransaction;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
......@@ -67,7 +68,6 @@ import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.support.v4.app.FragmentTransaction;
import com.actionbarsherlock.app.SherlockFragment;
......@@ -90,13 +90,13 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
public final static int SORT_BY_LENGTH = 1;
private boolean mSortReverse = false;
private int mSortBy = SORT_BY_TITLE;
public final static int MODE_ARTIST = 0;
public final static int MODE_ALBUM = 1;
public final static int MODE_SONG = 2;
public final static int MODE_GENRE = 3;
public final static int MODE_DIRECTORY = 4;
public final static int MENU_PLAY = Menu.FIRST;
public final static int MENU_APPEND = Menu.FIRST + 1;
public final static int MENU_PLAY_ALL = Menu.FIRST + 2;
......@@ -219,7 +219,7 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
return false;
String name = adapter.getGroup(groupPosition);
AudioListFragment audioList = new AudioListFragment();
Bundle b = new Bundle();
b.putString(AudioListFragment.EXTRA_NAME, name);
......@@ -242,7 +242,7 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
AudioPlaylistAdapter adapter = (AudioPlaylistAdapter) elv.getExpandableListAdapter();
String name = adapter.getGroup(groupPosition);
String child = adapter.getChild(groupPosition, childPosition);
AudioListFragment audioList = new AudioListFragment();
Bundle b = new Bundle();
b.putString(AudioListFragment.EXTRA_NAME, name);
......@@ -279,6 +279,7 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
.setMessage(R.string.validation)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
URI adressMediaUri = null;
try {
......@@ -294,7 +295,7 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
}
})
.setNegativeButton(android.R.string.cancel, null).create();
alertDialog.show();
}
......@@ -374,7 +375,7 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
super.onDestroy();
}
private ViewSwitchListener mViewSwitchListener = new ViewSwitchListener() {
private final ViewSwitchListener mViewSwitchListener = new ViewSwitchListener() {
int mCurrentPosition = 0;
......@@ -417,13 +418,15 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
}
};
private Comparator<Media> byMRL = new Comparator<Media>() {
private final Comparator<Media> byMRL = new Comparator<Media>() {
@Override
public int compare(Media m1, Media m2) {
return String.CASE_INSENSITIVE_ORDER.compare(m1.getLocation(), m2.getLocation());
};
};
private Comparator<Media> byLength = new Comparator<Media>() {
private final Comparator<Media> byLength = new Comparator<Media>() {
@Override
public int compare(Media m1, Media m2) {
if(m1.getLength() > m2.getLength()) return -1;
if(m1.getLength() < m2.getLength()) return 1;
......@@ -431,7 +434,8 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
};
};
private Comparator<Media> byAlbum = new Comparator<Media>() {
private final Comparator<Media> byAlbum = new Comparator<Media>() {
@Override
public int compare(Media m1, Media m2) {
int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getAlbum(), m2.getAlbum());
if (res == 0)
......@@ -440,7 +444,8 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
};
};
private Comparator<Media> byArtist = new Comparator<Media>() {
private final Comparator<Media> byArtist = new Comparator<Media>() {
@Override
public int compare(Media m1, Media m2) {
int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getArtist(), m2.getArtist());
if (res == 0)
......@@ -449,7 +454,8 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
};
};
private Comparator<Media> byGenre = new Comparator<Media>() {
private final Comparator<Media> byGenre = new Comparator<Media>() {
@Override
public int compare(Media m1, Media m2) {
int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getGenre(), m2.getGenre());
if (res == 0)
......@@ -508,6 +514,7 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
mDirectoryAdapter.notifyDataSetChanged();
}
@Override
public void sortBy(int sortby) {
if(mSortBy == sortby) {
mSortReverse = !mSortReverse;
......
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