Commit ed6ed949 authored by Adrien Maglo's avatar Adrien Maglo

MediaInfo: transform the activity into a secondary fragment

parent f0f0983d
......@@ -4,19 +4,6 @@
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="48dip"
android:background="@drawable/actionbar_background"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleType="centerInside"
android:src="@drawable/header_logo" />
</LinearLayout>
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
......@@ -48,7 +35,6 @@
android:layout_gravity="bottom|left"
android:layout_margin="10dip"
android:background="@drawable/ic_play"
android:onClick="onPlayClick"
android:visibility="invisible" />
<TextView
......
......@@ -37,6 +37,7 @@ import org.videolan.vlc.gui.SidebarAdapter.SidebarEntry;
import org.videolan.vlc.gui.audio.AudioAlbumsSongsFragment;
import org.videolan.vlc.gui.audio.AudioPlayer;
import org.videolan.vlc.gui.audio.EqualizerFragment;
import org.videolan.vlc.gui.video.MediaInfoFragment;
import org.videolan.vlc.gui.video.VideoListAdapter;
import org.videolan.vlc.interfaces.ISortable;
import org.videolan.vlc.widget.SlidingPaneLayout;
......@@ -115,7 +116,7 @@ public class MainActivity extends SherlockFragmentActivity {
private String mCurrentFragment;
private String mPreviousFragment;
private List<String> secondaryFragments = Arrays.asList("albumsSongs", "equalizer",
"about", "search");
"about", "search", "mediaInfo");
private HashMap<String, Fragment> mSecondaryFragments = new HashMap<String, Fragment>();
private SharedPreferences mSettings;
......@@ -488,6 +489,8 @@ public class MainActivity extends SherlockFragmentActivity {
f = new AboutFragment();
} else if(id.equals("search")) {
f = new SearchFragment();
} else if(id.equals("mediaInfo")) {
f = new MediaInfoFragment();
}
else {
throw new IllegalArgumentException("Wrong fragment id.");
......
......@@ -31,24 +31,29 @@ import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.WeakHandler;
import android.app.ListActivity;
import com.actionbarsherlock.app.SherlockListFragment;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
public class MediaInfoActivity extends ListActivity {
public class MediaInfoFragment extends SherlockListFragment {
public final static String TAG = "VLC/MediaInfoActivity";
public static final String KEY = "MediaInfoActivity.image";
public final static String TAG = "VLC/MediaInfoFragment";
private Media mItem;
private Bitmap mImage;
private TextView mTitleView;
private TextView mLengthView;
private ImageButton mPlayButton;
private TrackInfo[] mTracks;
private MediaInfoAdapter mAdapter;
......@@ -56,45 +61,46 @@ public class MediaInfoActivity extends ListActivity {
private final static int NEW_TEXT = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.media_info);
if (savedInstanceState != null)
mImage = savedInstanceState.getParcelable(KEY);
View v = inflater.inflate(R.layout.media_info, container, false);
String MRL = getIntent().getExtras().getString("itemLocation");
if (MRL == null)
return;
mItem = MediaLibrary.getInstance(this).getMediaItem(MRL);
if(mItem == null) {
// Shouldn't happen, maybe user opened it faster than Media Library could index it
return;
}
mTitleView = (TextView) v.findViewById(R.id.title);
mLengthView = (TextView) v.findViewById(R.id.length);
mPlayButton = (ImageButton) v.findViewById(R.id.play);
// set title
TextView titleView = (TextView) findViewById(R.id.title);
titleView.setText(mItem.getTitle());
// set length
TextView lengthView = (TextView) findViewById(R.id.length);
lengthView.setText(Util.millisToString(mItem.getLength()));
mPlayButton = (ImageButton) findViewById(R.id.play);
mPlayButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
VideoPlayerActivity.start(getActivity(), mItem.getLocation());
}
});
mAdapter = new MediaInfoAdapter(MediaInfoActivity.this);
mAdapter = new MediaInfoAdapter(getActivity());
setListAdapter(mAdapter);
new Thread(mLoadImage).start();
update();
return v;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(KEY, mImage);
public void setMediaLocation(String MRL) {
if (MRL == null)
return;
mItem = MediaLibrary.getInstance(getActivity()).getMediaItem(MRL);
}
public void onPlayClick(View v) {
VideoPlayerActivity.start(this, mItem.getLocation());
private void update() {
if (mItem == null) {
// Shouldn't happen, maybe user opened it faster than Media Library could index it
return;
}
mTitleView.setText(mItem.getTitle());
getSherlockActivity().getSupportActionBar().setTitle(mItem.getTitle());
mLengthView.setText(Util.millisToString(mItem.getLength()));
new Thread(mLoadImage).start();
}
Runnable mLoadImage = new Runnable() {
......@@ -110,30 +116,28 @@ public class MediaInfoActivity extends ListActivity {
mTracks = mLibVlc.readTracksInfo(mItem.getLocation());
mHandler.sendEmptyMessage(NEW_TEXT);
if (mImage == null) {
DisplayMetrics screen = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(screen);
int width = Math.min(screen.widthPixels, screen.heightPixels);
int height = width * 9 / 16;
DisplayMetrics screen = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(screen);
int width = Math.min(screen.widthPixels, screen.heightPixels);
int height = width * 9 / 16;
// Get the thumbnail.
mImage = Bitmap.createBitmap(width, height, Config.ARGB_8888);
// Get the thumbnail.
mImage = Bitmap.createBitmap(width, height, Config.ARGB_8888);
byte[] b = mLibVlc.getThumbnail(mItem.getLocation(), width, height);
byte[] b = mLibVlc.getThumbnail(mItem.getLocation(), width, height);
if (b == null) // We were not able to create a thumbnail for this item.
return;
if (b == null) // We were not able to create a thumbnail for this item.
return;
mImage.copyPixelsFromBuffer(ByteBuffer.wrap(b));
mImage = Util.cropBorders(mImage, width, height);
}
mImage.copyPixelsFromBuffer(ByteBuffer.wrap(b));
mImage = Util.cropBorders(mImage, width, height);
mHandler.sendEmptyMessage(NEW_IMAGE);
}
};
private void updateImage() {
ImageView imageView = (ImageView) MediaInfoActivity.this.findViewById(R.id.image);
ImageView imageView = (ImageView) getView().findViewById(R.id.image);
imageView.setImageBitmap(mImage);
mPlayButton.setVisibility(View.VISIBLE);
}
......@@ -147,14 +151,14 @@ public class MediaInfoActivity extends ListActivity {
private Handler mHandler = new MediaInfoHandler(this);
private static class MediaInfoHandler extends WeakHandler<MediaInfoActivity> {
public MediaInfoHandler(MediaInfoActivity owner) {
private static class MediaInfoHandler extends WeakHandler<MediaInfoFragment> {
public MediaInfoHandler(MediaInfoFragment owner) {
super(owner);
}
@Override
public void handleMessage(Message msg) {
MediaInfoActivity activity = getOwner();
MediaInfoFragment activity = getOwner();
if(activity == null) return;
switch (msg.what) {
......
......@@ -39,6 +39,7 @@ import org.videolan.vlc.VlcRunnable;
import org.videolan.vlc.WeakHandler;
import org.videolan.vlc.gui.CommonDialogs;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.audio.AudioAlbumsSongsFragment;
import org.videolan.vlc.interfaces.ISortable;
import android.annotation.TargetApi;
......@@ -289,9 +290,9 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
playAudio(media);
return true;
case R.id.video_list_info:
Intent intent = new Intent(getActivity(), MediaInfoActivity.class);
intent.putExtra("itemLocation", media.getLocation());
startActivity(intent);
MainActivity activity = (MainActivity)getActivity();
MediaInfoFragment frag = (MediaInfoFragment)activity.showSecondaryFragment("mediaInfo");
frag.setMediaLocation(media.getLocation());
return true;
case R.id.video_list_delete:
AlertDialog alertDialog = CommonDialogs.deleteMedia(
......
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