package net.neosum.android.nastore.gui;

import java.io.File;
import java.util.List;

import net.neosum.android.nastore.R;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

public class FileItems extends ArrayAdapter<FileItem>{
	private List<FileItem> fis;
	private BundleContext bc;

	public FileItems(Context context, int textViewResourceId,
			List<FileItem> objects,BundleContext bc) {
		super(context, textViewResourceId, objects);
		this.fis = objects;
		this.bc = bc;
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		   View v = convertView;
           if (v == null) 
           {
               LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
               v = vi.inflate(R.layout.flieitem, null);
               
           }
           final FileItem fi = fis.get(position);
           final File f = fi.getF();
           if (f != null && f.isFile()) {
                   TextView tt = (TextView) v.findViewById(R.id.fileTitleTv);
                   if (tt != null) {
                	   
           					tt.setText(f.getName());
                         
                    }
             Button instBtn = (Button) v.findViewById(R.id.installFileBtn);
             instBtn.setOnClickListener(new OnClickListener(){
				public void onClick(View v) {
					try {
						System.out.println("file://"+f.getAbsolutePath());
						Bundle bb = bc.installBundle("file://"+f.getAbsolutePath());
						if(bb != null)
						{
							bb.start();
							
						}
					} catch (BundleException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
             });
             
             Button uninstallBundleBtn = (Button) v.findViewById(R.id.deleteFileBtn);
             uninstallBundleBtn.setOnClickListener(new OnClickListener(){
				public void onClick(View v) {
					f.delete();
					fis.remove(fi);
					FileItems.this.notifyDataSetChanged();
				}
             });
           }
		return v;
	}
}

@@ -51,24 +51,94 @@
 va.io.File;%0A
+import java.io.FileInputStream;%0Aimport java.io.FileNotFoundException;%0A
 import java.
@@ -424,21 +424,32 @@
 iew.View
-Group
+.OnClickListener
 ;%0Aimport
@@ -466,32 +466,21 @@
 iew.View
-.OnClickListener
+Group
 ;%0Aimport
@@ -1830,22 +1830,40 @@
 ath());%0A
-%09%09%09%09%09%09
+                        
 Bundle b
@@ -1887,39 +1887,52 @@
 dle(
-%22file://%22+f.getAbsolutePath());
+f.getName(), new FileInputStream(f));%0A%09%09%09%09%09%09
 %0A%09%09%09
@@ -2095,22 +2095,182 @@
 race();%0A
-
 %09%09%09%09%09%7D
+ catch (FileNotFoundException e) %7B%0A                        // TODO Auto-generated catch block%0A                        e.printStackTrace();%0A                    %7D
 %0A%09%09%09%09%7D%0A 

install by InputStream instead of file:///blabla