From: <kro...@us...> - 2010-11-24 17:32:28
|
Revision: 3975 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=3975&view=rev Author: kroko_koenig Date: 2010-11-24 17:32:20 +0000 (Wed, 24 Nov 2010) Log Message: ----------- pictures almost finished, start work on mp3 saving Modified Paths: -------------- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/gen/mediaportal/remote/R.java trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/main.xml trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/pictures.xml trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/picturesfullscreen.xml trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/ImageAdapter.java trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/httpHandler.java trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/main.java trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures.java trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturesfullscreen.java trunk/plugins/AndroidRemote/Release/main.jpg trunk/plugins/AndroidRemote/Release/remote.jpg trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs trunk/plugins/AndroidRemote/Server/AndroidRemote.suo Added Paths: ----------- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/folder.png trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/folderback.png trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/nowplaying_logo.png trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/picture.png trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/icon.xml trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturehandler.java trunk/plugins/AndroidRemote/Release/folder.jpg trunk/plugins/AndroidRemote/Release/picture.jpg trunk/plugins/AndroidRemote/Release/settings.jpg Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/gen/mediaportal/remote/R.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/gen/mediaportal/remote/R.java 2010-11-24 13:13:47 UTC (rev 3974) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/gen/mediaportal/remote/R.java 2010-11-24 17:32:20 UTC (rev 3975) @@ -16,44 +16,52 @@ public static final int back_icon=0x7f020002; public static final int close_icon=0x7f020003; public static final int down_icon=0x7f020004; - public static final int icon=0x7f020005; - public static final int music_logo=0x7f020006; - public static final int next_icon=0x7f020007; - public static final int pictures_logo=0x7f020008; - public static final int play=0x7f020009; - public static final int remote_logo=0x7f02000a; - public static final int splash=0x7f02000b; - public static final int up_icon=0x7f02000c; - public static final int videos_logo=0x7f02000d; + public static final int folder=0x7f020005; + public static final int folderback=0x7f020006; + public static final int icon=0x7f020007; + public static final int music_logo=0x7f020008; + public static final int next_icon=0x7f020009; + public static final int nowplaying_logo=0x7f02000a; + public static final int picture=0x7f02000b; + public static final int pictures_logo=0x7f02000c; + public static final int play=0x7f02000d; + public static final int remote_logo=0x7f02000e; + public static final int splash=0x7f02000f; + public static final int up_icon=0x7f020010; + public static final int videos_logo=0x7f020011; } public static final class id { - public static final int Button01=0x7f050006; - public static final int GridView01=0x7f050007; - public static final int ImageView01=0x7f050008; - public static final int MainButton1=0x7f050000; - public static final int MainButton2=0x7f050001; - public static final int MainButton3=0x7f050002; - public static final int MainButton4=0x7f050003; - public static final int btnCancel=0x7f05000b; - public static final int btnDown=0x7f05000d; - public static final int btnLeft=0x7f05000f; - public static final int btnOk=0x7f05000c; - public static final int btnReturn=0x7f05000a; - public static final int btnReturnSetup=0x7f050012; - public static final int btnRight=0x7f05000e; - public static final int btnStartSetup=0x7f050004; - public static final int btnUp=0x7f050009; - public static final int server_ip=0x7f050010; - public static final int server_port=0x7f050011; - public static final int widget0=0x7f050005; + public static final int GridView01=0x7f050009; + public static final int ImageView01=0x7f05000b; + public static final int MainButton1=0x7f050003; + public static final int MainButton2=0x7f050004; + public static final int MainButton3=0x7f050005; + public static final int MainButton4=0x7f050006; + public static final int MainButton5=0x7f050007; + public static final int btnCancel=0x7f05000e; + public static final int btnDown=0x7f050010; + public static final int btnLeft=0x7f050012; + public static final int btnOk=0x7f05000f; + public static final int btnReturn=0x7f05000d; + public static final int btnReturnSetup=0x7f050015; + public static final int btnRight=0x7f050011; + public static final int btnUp=0x7f05000c; + public static final int full_text=0x7f05000a; + public static final int icon_image=0x7f050001; + public static final int icon_text=0x7f050002; + public static final int server_ip=0x7f050013; + public static final int server_port=0x7f050014; + public static final int widget0=0x7f050008; + public static final int widget44=0x7f050000; } public static final class layout { - public static final int main=0x7f030000; - public static final int pictures=0x7f030001; - public static final int picturesfullscreen=0x7f030002; - public static final int remote=0x7f030003; - public static final int setup=0x7f030004; - public static final int splash=0x7f030005; + public static final int icon=0x7f030000; + public static final int main=0x7f030001; + public static final int pictures=0x7f030002; + public static final int picturesfullscreen=0x7f030003; + public static final int remote=0x7f030004; + public static final int setup=0x7f030005; + public static final int splash=0x7f030006; } public static final class string { public static final int app_name=0x7f040001; Added: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/folder.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/folder.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/folderback.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/folderback.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/nowplaying_logo.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/nowplaying_logo.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/picture.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/drawable/picture.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/icon.xml =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/icon.xml (rev 0) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/icon.xml 2010-11-24 17:32:20 UTC (rev 3975) @@ -0,0 +1,23 @@ +<LinearLayout +xmlns:android="http://schemas.android.com/apk/res/android" +android:id="@+id/widget44" +android:layout_width="wrap_content" +android:layout_height="wrap_content" +android:orientation="vertical" +android:layout_x="201px" +android:layout_y="165px" +android:gravity="center_horizontal"> +<ImageView +android:id="@+id/icon_image" +android:layout_width="wrap_content" +android:layout_height="wrap_content"> +</ImageView> +<TextView +android:id="@+id/icon_text" +android:layout_width="wrap_content" +android:layout_height="wrap_content" +android:text="TextView" +android:gravity="center_horizontal" +android:textColorHighlight="#656565"> +</TextView> +</LinearLayout> \ No newline at end of file Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/main.xml =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/main.xml 2010-11-24 13:13:47 UTC (rev 3974) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/main.xml 2010-11-24 17:32:20 UTC (rev 3975) @@ -9,7 +9,7 @@ <Button android:id="@+id/MainButton1" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:padding="10dp" + android:padding="0dp" android:background="@drawable/pictures_logo" /> <View android:layout_height="2dp" android:layout_width="fill_parent" android:background="#000"/> @@ -17,7 +17,7 @@ <Button android:id="@+id/MainButton2" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:padding="10dp" + android:padding="0dp" android:background="@drawable/music_logo" /> <View android:layout_height="2dp" android:layout_width="fill_parent" android:background="#000"/> @@ -25,7 +25,7 @@ <Button android:id="@+id/MainButton3" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:padding="10dp" + android:padding="0dp" android:background="@drawable/videos_logo" /> <View android:layout_height="2dp" android:layout_width="fill_parent" android:background="#000"/> @@ -33,15 +33,15 @@ <Button android:id="@+id/MainButton4" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:padding="10dp" + android:padding="0dp" android:background="@drawable/remote_logo" /> <View android:layout_height="2dp" android:layout_width="fill_parent" android:background="#000"/> -<Button - android:id="@+id/btnStartSetup" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="Setup"></Button> +<Button android:id="@+id/MainButton5" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:padding="0dp" + android:background="@drawable/nowplaying_logo" /> </LinearLayout> Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/pictures.xml =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/pictures.xml 2010-11-24 13:13:47 UTC (rev 3974) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/pictures.xml 2010-11-24 17:32:20 UTC (rev 3975) @@ -5,9 +5,7 @@ android:background="@drawable/back" xmlns:android="http://schemas.android.com/apk/res/android" > -<Button android:text="Return" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> - -<GridView android:layout_y="60dip" +<GridView android:layout_y="0dip" android:layout_x="0dip" android:id="@+id/GridView01" android:layout_width="fill_parent" Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/picturesfullscreen.xml =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/picturesfullscreen.xml 2010-11-24 13:13:47 UTC (rev 3974) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/res/layout/picturesfullscreen.xml 2010-11-24 17:32:20 UTC (rev 3975) @@ -1,10 +1,19 @@ -<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/back" > +<TextView + android:id="@+id/full_text" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="name" + android:gravity="center_horizontal" + android:background="#FFFFFFFF" + android:textColor="#FF000000" + android:textColorHighlight="#FFFFFFFF"> +</TextView> <ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/ImageAdapter.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/ImageAdapter.java 2010-11-24 13:13:47 UTC (rev 3974) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/ImageAdapter.java 2010-11-24 17:32:20 UTC (rev 3975) @@ -22,62 +22,64 @@ import mediaportal.remote.httpHandler; - public class ImageAdapter extends BaseAdapter { - private Context mContext; + private Context mContext; - public ImageAdapter(Context c) { - mContext = c; - } + public ImageAdapter(Context c) { + mContext = c; + } - public int getCount() { - directoryItems myItems = directoryXmlHandler.getSitesList(); - return myItems.gettitle().size(); - } + public int getCount() { + directoryItems myItems = directoryXmlHandler.getSitesList(); + return myItems.gettitle().size(); + } - public Object getItem(int position) { - return null; - } + public Object getItem(int position) { + return null; + } - public long getItemId(int position) { - return 0; - } + public long getItemId(int position) { + return 0; + } - // create a new ImageView for each item referenced by the Adapter - public View getView(int position, View convertView, ViewGroup parent) { - ImageView imageView; - if (convertView == null) { // if it's not recycled, initialize some attributes - imageView = new ImageView(mContext); - imageView.setLayoutParams(new GridView.LayoutParams(85, 85)); - imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - imageView.setPadding(8, 8, 8, 8); - } else { - imageView = (ImageView) convertView; - } - - imageView.setImageBitmap(bmImg[position]); - return imageView; - } - - public static Bitmap[] bmImg; - public static Bitmap downloadFile(String fileUrl){ - URL myFileUrl =null; - try { - myFileUrl= new URL(fileUrl); - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - try { - HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection(); - conn.setReadTimeout(3000); - conn.setDoInput(true); - conn.connect(); - //int length = conn.getContentLength(); - InputStream is = conn.getInputStream(); - - SAXParserFactory spf = SAXParserFactory.newInstance(); - SAXParser sp = null; + // create a new ImageView for each item referenced by the Adapter + public View getView(int position, View convertView, ViewGroup parent) { + ImageView imageView; + if (convertView == null) { // if it's not recycled, initialize some + // attributes + imageView = new ImageView(mContext); + imageView.setLayoutParams(new GridView.LayoutParams(85, 85)); + imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + imageView.setPadding(8, 8, 8, 8); + } else { + imageView = (ImageView) convertView; + } + + imageView.setImageBitmap(bmImg[position]); + return imageView; + } + + public static Bitmap[] bmImg; + + public static Bitmap downloadFile(String fileUrl) { + URL myFileUrl = null; + try { + myFileUrl = new URL(fileUrl); + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + HttpURLConnection conn = (HttpURLConnection) myFileUrl + .openConnection(); + conn.setReadTimeout(3000); + conn.setDoInput(true); + conn.connect(); + // int length = conn.getContentLength(); + InputStream is = conn.getInputStream(); + + SAXParserFactory spf = SAXParserFactory.newInstance(); + SAXParser sp = null; try { sp = spf.newSAXParser(); } catch (ParserConfigurationException e) { @@ -87,8 +89,8 @@ // TODO Auto-generated catch block e.printStackTrace(); } - - XMLReader reader = null; + + XMLReader reader = null; try { reader = sp.getXMLReader(); } catch (SAXException e) { @@ -96,40 +98,39 @@ e.printStackTrace(); } - directoryXmlHandler handler = new directoryXmlHandler(); - - reader.setContentHandler(handler); - try { + directoryXmlHandler handler = new directoryXmlHandler(); + + reader.setContentHandler(handler); + try { reader.parse(new InputSource(is)); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } - is.close(); - sp.reset(); - - directoryItems myItems = directoryXmlHandler.getSitesList(); - bmImg = new Bitmap[myItems.gettitle().size()]; - - httpHandler h = new httpHandler(); - - for (int i = 0; i < myItems.gettitle().size(); i++) - { - String tit = myItems.gettitle().get(i); - //Boolean fold = myItems.getIsFolder().get(i); - - tit = tit + ".thb"; - - bmImg[i] = h.DownloadImage("http://192.6.10.182:8200/pictures/" + tit); - } - - - //bmImg = BitmapFactory.decodeStream(is); - return null; - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } + is.close(); + sp.reset(); + + directoryItems myItems = directoryXmlHandler.getSitesList(); + bmImg = new Bitmap[myItems.gettitle().size()]; + + httpHandler h = new httpHandler(); + + for (int i = 0; i < myItems.gettitle().size(); i++) { + String tit = myItems.gettitle().get(i); + // Boolean fold = myItems.getIsFolder().get(i); + + tit = tit + ".thb"; + + bmImg[i] = h.DownloadImage("http://192.6.10.182:8200/pictures/" + + tit); + } + + // bmImg = BitmapFactory.decodeStream(is); + return null; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } } \ No newline at end of file Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/httpHandler.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/httpHandler.java 2010-11-24 13:13:47 UTC (rev 3974) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/httpHandler.java 2010-11-24 17:32:20 UTC (rev 3975) @@ -1,16 +1,28 @@ package mediaportal.remote; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; + +import org.apache.http.util.ByteArrayBuffer; + import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.os.Environment; +import android.widget.Toast; public class httpHandler { + String extStorageDirectory; + public httpHandler() { } @@ -67,4 +79,39 @@ } + public void DownloadFile() { + extStorageDirectory = Environment.getExternalStorageDirectory() + .toString(); + + try { + InputStream in = openHttpConnection("http://192.168.0.30:8200/music/Clementi_Sonatina_Op.36_No.1_Movement_1.mp3"); + + //BufferedInputStream bis = new BufferedInputStream(in); + ByteArrayBuffer baf = new ByteArrayBuffer(50); + int current = 0; + + byte[] bb = new byte[1024]; + int l = in.read(bb,0,1024); + + while (l > -0) { + baf.append(bb, 0, l); + l = in.read(bb,0,1024); + } + + OutputStream outStream = null; + File file = new File(extStorageDirectory, "test.mp3"); + + outStream = new FileOutputStream(file); + outStream.write(baf.toByteArray()); + outStream.flush(); + outStream.close(); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/main.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/main.java 2010-11-24 13:13:47 UTC (rev 3974) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/main.java 2010-11-24 17:32:20 UTC (rev 3975) @@ -11,8 +11,6 @@ public class main extends Activity { - public static String SelectedPicture; - /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { @@ -35,11 +33,11 @@ } }); - Button btnSetup = (Button) findViewById(R.id.btnStartSetup); - btnSetup.setOnClickListener(new View.OnClickListener() { + Button btnNowPlaying = (Button) findViewById(R.id.MainButton5); + btnNowPlaying.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { - Intent myIntent = new Intent(view.getContext(), setup.class); - startActivityForResult(myIntent, 0); + httpHandler h = new httpHandler(); + h.DownloadFile(); } }); Added: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturehandler.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturehandler.java (rev 0) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturehandler.java 2010-11-24 17:32:20 UTC (rev 3975) @@ -0,0 +1,163 @@ +package mediaportal.remote; + +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLEncoder; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +import android.graphics.Bitmap; + +import mediaportal.remote.directoryItems; + +public class picturehandler { + + public static final String PREFS_PRIVATE = "PREFS_MP_REMOTE"; + + private static directoryItems pictures; + private static picturehandler instance; + + private static String actualDir = ""; + + private String _server; + private String _port; + + public int selectedPicture; + public String selectedPictureName = ""; + + public Bitmap getselectedPicture() { + + String act = pictures.gettitle().get(selectedPicture); + String dir = actualDir + "/" + act; + selectedPictureName = act; + + try { + dir = URLEncoder.encode(dir, "UTF-8"); + } catch (UnsupportedEncodingException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + String fileUrl = "http://" + _server + ":" + _port + "/" + dir; + httpHandler h = new httpHandler(); + return h.DownloadImage(fileUrl); + } + + public static picturehandler getinstance() { + if (instance == null) + instance = new picturehandler(); + return instance; + } + + private picturehandler() { + pictures = new directoryItems(); + } + + public void setconnection(String server, String port) { + _server = server; + _port = port; + } + + public directoryItems getpictures() { + return pictures; + } + + public void getrootdirectory() { + actualDir = "pictures"; + fetchdirectory(actualDir); + } + + private void fetchdirectory(String dir) { + pictures = new directoryItems(); + try { + dir = URLEncoder.encode(dir, "UTF-8"); + } catch (UnsupportedEncodingException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + String fileUrl = "http://" + _server + ":" + _port + "/" + dir; + + URL myFileUrl = null; + try { + myFileUrl = new URL(fileUrl); + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + HttpURLConnection conn = (HttpURLConnection) myFileUrl + .openConnection(); + conn.setReadTimeout(10000); + conn.setDoInput(true); + conn.connect(); + // int length = conn.getContentLength(); + InputStream is = conn.getInputStream(); + + SAXParserFactory spf = SAXParserFactory.newInstance(); + SAXParser sp = null; + try { + sp = spf.newSAXParser(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + XMLReader reader = null; + try { + reader = sp.getXMLReader(); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + directoryXmlHandler handler = new directoryXmlHandler(); + + reader.setContentHandler(handler); + try { + reader.parse(new InputSource(is)); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + is.close(); + sp.reset(); + + pictures = directoryXmlHandler.getSitesList(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void gotodir(String dir) { + actualDir += "/" + dir; + fetchdirectory(actualDir); + } + + public void oneup() { + int x = actualDir.lastIndexOf("/"); + if (x >= 0) { + actualDir = actualDir.substring(0, x); + } + fetchdirectory(actualDir); + } + + public String getactualdir() { + return actualDir; + } +} Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures.java 2010-11-24 13:13:47 UTC (rev 3974) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures.java 2010-11-24 17:32:20 UTC (rev 3975) @@ -1,64 +1,172 @@ package mediaportal.remote; import mediaportal.remote.R; -import mediaportal.remote.ImageAdapter; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.AdapterView; +import android.widget.BaseAdapter; import android.widget.Button; import android.widget.GridView; +import android.widget.ImageView; +import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; +import mediaportal.remote.picturehandler; public class pictures extends Activity { - + public static final String PREFS_PRIVATE = "PREFS_MP_REMOTE"; - + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pictures); - SharedPreferences settings = getSharedPreferences(PREFS_PRIVATE , MODE_PRIVATE); + SharedPreferences settings = getSharedPreferences(PREFS_PRIVATE, + MODE_PRIVATE); String HttpServer = settings.getString("Server", "192.168.0.30"); String HttpPort = settings.getString("Port", "8200"); - ImageAdapter.downloadFile("http://" + HttpServer + ":" + HttpPort - + "/pictures/2010/2008%2001%2023"); + // ImageAdapter.downloadFile("http://" + HttpServer + ":" + HttpPort + // + "/pictures/2010/2008%2001%2023"); + picturehandler h = picturehandler.getinstance(); + h.setconnection(HttpServer, HttpPort); + h.getrootdirectory(); + GridView gridview = (GridView) findViewById(R.id.GridView01); - gridview.setAdapter(new ImageAdapter(this)); + gridview.setAdapter(new ImageAdapter2(this)); - Button ret = (Button) findViewById(R.id.Button01); - ret.setOnClickListener(new View.OnClickListener() { - public void onClick(View view) { - Intent intent = new Intent(); - setResult(RESULT_OK, intent); - finish(); - } - }); - gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { - SharedPreferences settings = getPreferences(MODE_PRIVATE); + TextView tv = (TextView) v.findViewById(R.id.icon_text); + ImageView iv = (ImageView) v.findViewById(R.id.icon_image); + picItem pic = (picItem) iv.getTag(); - String HttpServer = settings - .getString("Server", "192.168.0.30"); - String HttpPort = settings.getString("Port", "8200"); + if (pic.typ == "item") { + picturehandler h = picturehandler.getinstance(); + h.selectedPicture = position - 1; - main.SelectedPicture = "http://" + HttpServer + ":" + HttpPort - + "/pictures/2010/2008%2001%2023/sdc10839.jpg"; - Intent myIntent = new Intent(v.getContext(), - picturesfullscreen.class); - startActivityForResult(myIntent, 0); + Intent myIntent = new Intent(v.getContext(), + picturesfullscreen.class); + startActivityForResult(myIntent, 0); + } + + if (pic.typ == "folder") { + + picturehandler h = picturehandler.getinstance(); + h.gotodir(pic.title); + + GridView gridview = (GridView) findViewById(R.id.GridView01); + gridview.setAdapter(new ImageAdapter2(parent.getContext())); + + parent.invalidate(); + } + + if (pic.typ == "oneup") { + picturehandler h = picturehandler.getinstance(); + h.oneup(); + + GridView gridview = (GridView) findViewById(R.id.GridView01); + gridview.setAdapter(new ImageAdapter2(parent.getContext())); + + parent.invalidate(); + } + } }); } + + public class ImageAdapter2 extends BaseAdapter { + private Context mContext; + public static final int ACTIVITY_CREATE = 10; + + public ImageAdapter2(Context c) { + mContext = c; + } + + public int getCount() { + picturehandler h = picturehandler.getinstance(); + return h.getpictures().gettitle().size() + 1; + } + + public Object getItem(int position) { + return null; + } + + public long getItemId(int position) { + return 0; + } + + // @Override + // create a new ImageView for each item referenced by the Adapter + public View getView(int position, View convertView, ViewGroup parent) { + View v; + if (convertView == null) { // if it's not recycled, initialize some + // attributes + + if (position > 0) { + position = position - 1; + + picturehandler h = picturehandler.getinstance(); + String txtName = h.getpictures().gettitle().get(position); + Boolean isFolder = h.getpictures().getIsFolder() + .get(position); + + LayoutInflater li = LayoutInflater.from(mContext); + v = li.inflate(R.layout.icon, null); + TextView tv = (TextView) v.findViewById(R.id.icon_text); + tv.setText(txtName); // ("Profile "+position); + ImageView iv = (ImageView) v.findViewById(R.id.icon_image); + + if (isFolder) { + iv.setImageResource(R.drawable.folder); + picItem pic = new picItem(); + pic.title = txtName; + pic.typ = "folder"; + iv.setTag(pic); + } else { + iv.setImageResource(R.drawable.picture); + picItem pic = new picItem(); + pic.title = txtName; + pic.typ = "item"; + iv.setTag(pic); + } + } else { + LayoutInflater li = LayoutInflater.from(mContext); + v = li.inflate(R.layout.icon, null); + TextView tv = (TextView) v.findViewById(R.id.icon_text); + tv.setText(".."); // ("Profile "+position); + ImageView iv = (ImageView) v.findViewById(R.id.icon_image); + iv.setImageResource(R.drawable.folderback); + picItem pic = new picItem(); + pic.title = ".."; + pic.typ = "oneup"; + iv.setTag(pic); + } + + } else { + v = convertView; + } + + // imageView.setImageBitmap(bmImg[position]); + return v; + } + } + + public class picItem { + public String title; + public String typ; + } + } Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturesfullscreen.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturesfullscreen.java 2010-11-24 13:13:47 UTC (rev 3974) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturesfullscreen.java 2010-11-24 17:32:20 UTC (rev 3975) @@ -4,29 +4,111 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.view.GestureDetector; +import android.view.GestureDetector.OnGestureListener; +import android.view.GestureDetector.SimpleOnGestureListener; +import android.view.LayoutInflater.Filter; +import android.view.MotionEvent; import android.view.View; +import android.view.View.OnClickListener; import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; -public class picturesfullscreen extends Activity { +public class picturesfullscreen extends Activity implements OnGestureListener { + private static final int SWIPE_MIN_DISTANCE = 120; + private static final int SWIPE_MAX_OFF_PATH = 250; + private static final int SWIPE_THRESHOLD_VELOCITY = 200; + + private GestureDetector gestureScanner; + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.picturesfullscreen); - httpHandler h = new httpHandler(); + gestureScanner = new GestureDetector(this); ImageView imagev = (ImageView) findViewById(R.id.ImageView01); - imagev.setImageBitmap(h.DownloadImage(main.SelectedPicture)); + picturehandler pic = picturehandler.getinstance(); + imagev.setImageBitmap(pic.getselectedPicture()); - imagev.setOnClickListener(new View.OnClickListener() { - public void onClick(View view) { - Intent intent = new Intent(); - setResult(RESULT_OK, intent); - finish(); + TextView txt = (TextView) findViewById(R.id.full_text); + txt.setText(pic.selectedPictureName); + + /* + * imagev.setOnClickListener(new View.OnClickListener() { public void + * onClick(View view) { Intent intent = new Intent(); + * setResult(RESULT_OK, intent); finish(); } }); + */ + + } + + @Override + public boolean onTouchEvent(MotionEvent me) { + return gestureScanner.onTouchEvent(me); + } + + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, + float velocityY) { + try { + if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) + return false; + // right to left swipe + if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE + && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { + Toast.makeText(picturesfullscreen.this, "Left Swipe", + Toast.LENGTH_SHORT).show(); + picturehandler pic = picturehandler.getinstance(); + pic.selectedPicture += 1; + if(pic.selectedPicture>=pic.getpictures().gettitle().size()) + pic.selectedPicture = 0; + ImageView imagev = (ImageView) findViewById(R.id.ImageView01); + imagev.setImageBitmap(pic.getselectedPicture()); + TextView txt = (TextView) findViewById(R.id.full_text); + txt.setText(pic.selectedPictureName); + + } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE + && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { + Toast.makeText(picturesfullscreen.this, "Right Swipe", + Toast.LENGTH_SHORT).show(); + picturehandler pic = picturehandler.getinstance(); + pic.selectedPicture -= 1; + if(pic.selectedPicture<=0) + pic.selectedPicture = pic.getpictures().gettitle().size(); + ImageView imagev = (ImageView) findViewById(R.id.ImageView01); + imagev.setImageBitmap(pic.getselectedPicture()); + TextView txt = (TextView) findViewById(R.id.full_text); + txt.setText(pic.selectedPictureName); } - }); + } catch (Exception e) { + String g = e.getStackTrace().toString(); + // nothing + } + return false; + } + + public boolean onDown(MotionEvent arg0) { + // TODO Auto-generated method stub + return true; + } + public void onLongPress(MotionEvent arg0) { + // TODO Auto-generated method stub } + public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, + float arg3) { + // TODO Auto-generated method stub + return false; + } + public void onShowPress(MotionEvent arg0) { + // TODO Auto-generated method stub + + } + public boolean onSingleTapUp(MotionEvent arg0) { + // TODO Auto-generated method stub + return false; + } } \ No newline at end of file Added: trunk/plugins/AndroidRemote/Release/folder.jpg =================================================================== (Binary files differ) Property changes on: trunk/plugins/AndroidRemote/Release/folder.jpg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/plugins/AndroidRemote/Release/main.jpg =================================================================== (Binary files differ) Added: trunk/plugins/AndroidRemote/Release/picture.jpg =================================================================== (Binary files differ) Property changes on: trunk/plugins/AndroidRemote/Release/picture.jpg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/plugins/AndroidRemote/Release/remote.jpg =================================================================== (Binary files differ) Added: trunk/plugins/AndroidRemote/Release/settings.jpg =================================================================== (Binary files differ) Property changes on: trunk/plugins/AndroidRemote/Release/settings.jpg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs =================================================================== --- trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs 2010-11-24 13:13:47 UTC (rev 3974) +++ trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs 2010-11-24 17:32:20 UTC (rev 3975) @@ -45,8 +45,6 @@ private byte[] read; private byte[] buffer; - private static Dictionary<string, Bitmap> pictureList = new Dictionary<string, Bitmap>(); - private static Dictionary<string, Bitmap> pictureThumbList = new Dictionary<string, Bitmap>(); private static Dictionary<string, string> musicList = new Dictionary<string, string>(); public Request(Socket Socket) @@ -73,7 +71,6 @@ else { allMessage = allMessage + clientmessage.Substring(0, bytes); - System.Diagnostics.Debug.WriteLine(allMessage); if (clientmessage.Contains("POST")) { @@ -91,6 +88,8 @@ req = HttpUtility.UrlDecode(req); + System.Diagnostics.Debug.WriteLine("GET Request : " + req); + #region pictures if (req.StartsWith("/pictures")) { @@ -110,12 +109,12 @@ if (req.EndsWith(".jpg")) { string orgPath = AndroidServer.PicturePath + "\\" + req; - ReplyPictureFile(Path.GetFileName(orgPath)); + ReplyPictureFile(orgPath); } else if (req.EndsWith(".thb")) { string orgPath = AndroidServer.PicturePath + "\\" + req; - ReplyPictureThumbFile(Path.GetFileName(orgPath)); + ReplyPictureThumbFile(orgPath); } else { @@ -217,9 +216,6 @@ { if (Directory.Exists(dir)) { - pictureList.Clear(); - pictureThumbList.Clear(); - string msg = string.Empty; // header msg += "HTTP/1.0 200 Ok\r\n"; @@ -239,21 +235,7 @@ string[] files = Directory.GetFiles(dir, "*.jpg", SearchOption.TopDirectoryOnly); foreach (string f in files) { - string name = Path.GetFileName(f).ToLower(); - Image img = null; - try - { - img = Bitmap.FromFile(f); - } - catch { } - if (img != null) - { - pictureList.Add(name, (Bitmap)img); - Bitmap thumb = (Bitmap)img.Clone(); - thumb = MediaPortal.Util.BitmapResize.Resize(ref thumb, 85, 85, false, true); - pictureThumbList.Add(name, thumb); - } - msg += "<File>" + name + "</File>\r\n"; + msg += "<File>" + Path.GetFileName(f) + "</File>\r\n"; } msg += "</Directory>\r\n"; // send @@ -265,11 +247,11 @@ SendErrorURL(request); } } - private void ReplyPictureFile(string File) + private void ReplyPictureFile(string filePath) { - if (pictureThumbList.ContainsKey(File)) + if (File.Exists(filePath)) { - Bitmap bit = pictureList[File]; + Bitmap bit = (Bitmap)Bitmap.FromFile(filePath); byte[] b; if ((bit.Width > 600) || (bit.Height > 600)) @@ -299,25 +281,26 @@ } else { - SendErrorFile(File); + SendServerError(filePath,"ReplyPictureFile"); } } else { - SendErrorFile(File); + SendErrorFile(filePath); } } - private void ReplyPictureThumbFile(string File) + private void ReplyPictureThumbFile(string filePath) { - /// - /// we might do cache the thumb different later, right now you need to request the dir first - /// - File = File.Replace(".thb", ""); - if (pictureThumbList.ContainsKey(File)) + if (File.Exists(filePath)) { - Bitmap bit = pictureThumbList[File]; - byte[] b = BildToByteArray((Image)bit); + Bitmap bit = (Bitmap)Bitmap.FromFile(filePath); + byte[] b; + Bitmap thumb = (Bitmap)bit.Clone(); + thumb = MediaPortal.Util.BitmapResize.Resize(ref thumb, 85, 85, false, true); + + b = BildToByteArray((Image)thumb); + if (b != null) { string msg = string.Empty; @@ -333,12 +316,12 @@ } else { - SendErrorFile(File); + SendServerError(filePath, "ReplyPictureThumbFile"); } } else { - SendErrorFile(File); + SendErrorFile(filePath); } } @@ -441,6 +424,7 @@ private void SendErrorURL(string Url) { + System.Diagnostics.Debug.WriteLine("URL NOT FOUND " + Url); string msg = string.Empty; // header msg += "HTTP/1.0 404 Not Found\r\n"; @@ -460,8 +444,9 @@ // send sendMessage(socket, msg); } - private void SendErrorFile(string File) + private void SendErrorFile(string FileName) { + System.Diagnostics.Debug.WriteLine("FILE NOT FOUND " + FileName); string msg = string.Empty; // header msg += "HTTP/1.0 404 Not Found\r\n"; @@ -474,13 +459,35 @@ msg += "<title>404 Not Found</title>" + "\r\n"; msg += "</head><body>" + "\r\n"; msg += "<h1>Not Found</h1>" + "\r\n"; - msg += "<p>The requested file " + File + " was not found on this server.</p>" + "\r\n"; + msg += "<p>The requested file " + FileName + " was not found on this server.</p>" + "\r\n"; msg += "<hr>" + "\r\n"; msg += "<address>TeamMediaportal Server at " + AndroidServer.Server + " Port " + AndroidServer.Port + "</address>" + "\r\n"; msg += "</body></html>" + "\r\n"; // send sendMessage(socket, msg); } + private void SendServerError(string Data, string Who) + { + System.Diagnostics.Debug.WriteLine("Internal Server Error " + Who); + string msg = string.Empty; + // header + msg += "HTTP/1.0 500 Internal Server Error\r\n"; + msg += "Content-Type: text/html; charset=utf-8" + "\r\n"; + msg += "Proxy-Connection: close" + "\r\n"; + msg += "\r\n"; + // message + msg += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"; + msg += "<html><head>" + "\r\n"; + msg += "<title>404 Not Found</title>" + "\r\n"; + msg += "</head><body>" + "\r\n"; + msg += "<h1>Not Found</h1>" + "\r\n"; + msg += "<p>The requested data " + Data + " causes a problem.</p>" + "\r\n"; + msg += "<hr>" + "\r\n"; + msg += "<address>TeamMediaportal Server at " + AndroidServer.Server + " Port " + AndroidServer.Port + "</address>" + "\r\n"; + msg += "</body></html>" + "\r\n"; + // send + sendMessage(socket, msg); + } private int readmessage(byte[] ByteArray, ref Socket s, ref String clientmessage) { Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote.suo =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |