Commit 2ea9f5a5 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Show file size in info fragment

parent dec2319a
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:baselineAligned="false"
android:orientation="horizontal"
android:background="@color/white" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal"
android:background="@color/white" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<FrameLayout
android:layout_width="0dp"
android:id="@+id/image_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
android:layout_alignParentTop="true">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
......@@ -50,17 +52,29 @@
android:textColor="@color/white"
android:visibility="invisible" />
</FrameLayout>
<ListView
android:id="@id/android:list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:clipToPadding="false"
android:divider="#00000000"
android:fastScrollEnabled="true"
android:listSelector="@android:color/transparent"
android:paddingBottom="@dimen/listview_bottom_padding" />
</LinearLayout>
<TextView
android:id="@+id/size_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/file_size"
android:layout_marginRight="5dp"
android:layout_below="@+id/image_container"/>
<TextView
android:id="@+id/size_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image_container"
android:layout_toRightOf="@+id/size_title"/>
</RelativeLayout>
<ListView
android:id="@id/android:list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:clipToPadding="false"
android:divider="#00000000"
android:fastScrollEnabled="true"
android:listSelector="@android:color/transparent"
android:paddingBottom="@dimen/listview_bottom_padding" />
</LinearLayout>
\ No newline at end of file
......@@ -5,44 +5,63 @@
android:background="@color/white"
android:orientation="vertical" >
<FrameLayout
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/image_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="25dp"
android:scaleType="fitCenter" />
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="25dp"
android:scaleType="fitCenter" />
<ImageButton
android:id="@+id/play"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_gravity="bottom|right"
android:layout_marginRight="10dip"
android:background="@drawable/ic_play_circle_big_o"
android:visibility="invisible" />
<ImageButton
android:id="@+id/play"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_gravity="bottom|right"
android:layout_marginRight="10dip"
android:background="@drawable/ic_play_circle_big_o"
android:visibility="invisible" />
<TextView
android:id="@+id/length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:layout_marginLeft="10dip"
android:layout_marginBottom="25dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:visibility="invisible" />
</FrameLayout>
<TextView
android:id="@+id/size_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/file_size"
android:layout_marginLeft="30dp"
android:layout_marginRight="5dp"
android:layout_below="@+id/image_container"/>
<TextView
android:id="@+id/length"
android:id="@+id/size_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:layout_marginLeft="10dip"
android:layout_marginBottom="25dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:visibility="invisible" />
</FrameLayout>
android:layout_below="@+id/image_container"
android:layout_toRightOf="@+id/size_title"/>
</RelativeLayout>
<ListView
android:id="@id/android:list"
......
......@@ -307,6 +307,9 @@
<string name="drawer_open">Open navigation drawer</string>
<string name="drawer_close">Close navigation drawer</string>
<string name="file_size">File size:</string>
<string name="file_other">Close navigation drawer</string>
<string-array name="hardware_acceleration_list">
<item>@string/automatic</item>
<item>@string/hardware_acceleration_disabled</item>
......
......@@ -20,6 +20,7 @@
package org.videolan.vlc.gui.video;
import java.io.File;
import java.nio.ByteBuffer;
import org.videolan.libvlc.LibVLC;
......@@ -37,6 +38,7 @@ import org.videolan.vlc.util.WeakHandler;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
......@@ -54,14 +56,18 @@ import android.widget.TextView;
public class MediaInfoFragment extends ListFragment {
public final static String TAG = "VLC/MediaInfoFragment";
LibVLC mLibVlc = null;
private Media mItem;
private Bitmap mImage;
private TextView mLengthView;
private TextView mSizeView;
private ImageButton mPlayButton;
private TrackInfo[] mTracks;
private MediaInfoAdapter mAdapter;
private final static int NEW_IMAGE = 0;
private final static int NEW_TEXT = 1;
private final static int NEW_SIZE = 2;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
......@@ -69,6 +75,7 @@ public class MediaInfoFragment extends ListFragment {
View v = inflater.inflate(R.layout.media_info, container, false);
mLengthView = (TextView) v.findViewById(R.id.length);
mSizeView = (TextView) v.findViewById(R.id.size_value);
mPlayButton = (ImageButton) v.findViewById(R.id.play);
mPlayButton.setOnClickListener(new OnClickListener() {
......@@ -97,6 +104,7 @@ public class MediaInfoFragment extends ListFragment {
mLengthView.setText(Strings.millisToString(mItem.getLength()));
new Thread(mLoadImage).start();
new Thread(mLoadSize).start();
}
public void setMediaLocation(String MRL) {
......@@ -105,10 +113,18 @@ public class MediaInfoFragment extends ListFragment {
mItem = MediaLibrary.getInstance().getMediaItem(MRL);
}
Runnable mLoadSize = new Runnable() {
@Override
public void run() {
File itemFile = new File(Uri.decode(mItem.getLocation().substring(5)));
long length = itemFile.length();
mHandler.obtainMessage(NEW_SIZE, Long.valueOf(length)).sendToTarget();
}
};
Runnable mLoadImage = new Runnable() {
@Override
public void run() {
LibVLC mLibVlc = null;
try {
mLibVlc = VLCInstance.getLibVlcInstance();
} catch (LibVlcException e) {
......@@ -166,10 +182,15 @@ public class MediaInfoFragment extends ListFragment {
if (track.Type != TrackInfo.TYPE_META)
mAdapter.add(track);
}
if (mAdapter.isEmpty())
((MainActivity)getActivity()).popSecondaryFragment();
if (mAdapter.isEmpty()) {
((MainActivity) getActivity()).popSecondaryFragment();
return;
}
}
private void updateSize(Long size){
mSizeView.setText(Strings.readableFileSize(size.longValue()));
}
private Handler mHandler = new MediaInfoHandler(this);
private static class MediaInfoHandler extends WeakHandler<MediaInfoFragment> {
......@@ -179,15 +200,18 @@ public class MediaInfoFragment extends ListFragment {
@Override
public void handleMessage(Message msg) {
MediaInfoFragment activity = getOwner();
if(activity == null) return;
MediaInfoFragment fragment = getOwner();
if(fragment == null) return;
switch (msg.what) {
case NEW_IMAGE:
activity.updateImage();
fragment.updateImage();
break;
case NEW_TEXT:
activity.updateText();
fragment.updateText();
break;
case NEW_SIZE:
fragment.updateSize((Long) msg.obj);
break;
}
};
......
......@@ -104,4 +104,11 @@ public class Strings {
public static String formatRateString(float rate) {
return String.format(java.util.Locale.US, "%.2fx", rate);
}
public static String readableFileSize(long size) {
if(size <= 0) return "0";
final String[] units = new String[] { "B", "kB", "MB", "GB", "TB" };
int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
}
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