import java.io.InputStream;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class startup extends UiApplication{
public static void main(String[] args) {
startup start=new startup();
start.enterEventDispatcher();
}
public startup() {
pushScreen(new ImageView());
}
}
public class ImageView extends MainScreen
{
VerticalFieldManager vmgr;
private String filepath="file:///SDCard/images/";
public ImageView()
{
initGUI();
}
public void initGUI()
{
try
{
vmgr=new VerticalFieldManager(USE_ALL_HEIGHT|USE_ALL_WIDTH);
Vector images= getList(filepath);
for(int i=0;i<images.size();i++)
{
Bitmap bit=getData(filepath+images.elementAt(i));
Bitmap scale=new Bitmap(Display.getWidth(), 300);
bit.scaleInto(scale, Bitmap.FILTER_LANCZOS);
BitmapField field=new BitmapField(scale,Field.FOCUSABLE);
vmgr.add(field);
}
add(vmgr);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
public Vector getList(String url)
{
Vector contentVector=null;
FileConnection fileConnection=null;
try{
fileConnection = (FileConnection) Connector.open(url);
if (fileConnection.isDirectory()) {
Enumeration directoryEnumerator = fileConnection.list();
contentVector = new Vector();
while (directoryEnumerator.hasMoreElements()) {
contentVector.addElement(directoryEnumerator.nextElement());
}
}
}catch (Exception e) {
}
finally{
if(fileConnection!=null){
try {
fileConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return contentVector;
}
private Bitmap getData(String url)
{
Bitmap bit_img=null;
byte[] data = new byte[0];
try
{
FileConnection file = (FileConnection)Connector.open(url);
int fileSize = (int)file.fileSize();
data = new byte[fileSize];
InputStream inputStream = file.openInputStream();
inputStream.read(data);
EncodedImage bitmap = EncodedImage.createEncodedImage(data, 0,data.length);
bit_img=bitmap.getBitmap();
}
catch(Exception e)
{
System.out.println(e.toString());
}
return bit_img;
}
}