Powered By Blogger

Friday 23 December 2011

Retrive images from Sdcard


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;         
     }
}

Thursday 22 December 2011

Blackberry application installation in to the mobile

Hi after signing project successfully we can find two types of files in Deliverables
1)standard 2)Web
in Standard Folder we can find
1)version number(if OS is 5.0 then we can find it 5.0.0)
2)projectname.alx
open that 5.0.0 folder here we can find many file types like .debug, .cod, csl, .cso ,.jar ,.jad ,.rapc these all are configuration files
NOTE:WE CAN FIND ONLY ONE .COD FILE AND .JAD FILE COPY THAT TWO FILES INTO ANY FILE SYSTEM INTO PC
Now open that .cod file and extract the all files into one particular folder suppose in my pc desktop i create a folder name DEVISEDEMO
i extract all .cod files into DEVISEDEMO Folder.
next i copy that .jad files into DEVISEDEMO folder
now i copy that DEVISEDEMO folder into Blackberry mobile SDCARD using any data cable
Now i disconnect that mobile from pc and open Memorycard ----> DEVISEDEMO after that click on .jad file now it can download all data regarding application after successfully installed one dialog will open.
This is one process otherwise copy all .cod and .jad files which are appear in the web folder to sdcard and after that same process
NOTE: YOU CAN NOT COMPARE ANDROID AND BLACKBERRY BECAUSE .APK FILE SIZE IS NOT RESTRICTED BUT BLACKBERRY WHEN WE SUCCESSFULLY SIGN THEN IT WILL CONVERT INTO .COD FILES MEANS SYSTEM UNDERSTANDABLE LANGUAGE. impermanent THING IS THAT ONE COD FILE CAN ONLY STORE 64KB DATA. IF IT CROSSED IT SIZE IT AUTOMATICALLY CREATE NEW .COD FILE. SO WE HAVE TO KEEP TRACK THESE INFORMATION WHICH FILE CONTINUATION IS WHICH FILE. FOR THIS PURPOSE .JAD FILE CAN KEEP ALL .COD FILES INFORMATION
if i made any wrong statements please correct that

Custom List view in blackberry

class sampleScreen extends MainScreen implements FieldChangeListener
{
    private CustomListField cu_field[];
    private Bitmap image=null;
    int size=8;
    public sampleScreen() {
        VerticalFieldManager vmanager=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR){
            protected void sublayout(int maxWidth, int maxHeight) {
               
                super.sublayout(Display.getWidth(),Display.getHeight());
                setExtent(Display.getWidth(),Display.getHeight());
            }
        };
        cu_field=new CustomListField[size];
        for(int i=0;i<size;i++){
            image=Bitmap.getBitmapResource("sample_"+i+".jpg");
            cu_field[i]=new CustomListField("BlackBerry models that had a built-in mobile phone, were the first models that natively ran Java, and transmitted data over the normal 2G cellular network. RIM began to advertise these devices as email-capable mobile phones rather than as 2-way pagers.", image, "jan2011", 100, 100,Color.RED);
            cu_field[i].setChangeListener(this);
            vmanager.add(new SeparatorField());
            vmanager.add(cu_field[i]);
        }
        add(vmanager);
    }

    public void fieldChanged(Field field, int context) {
        // TODO Auto-generated method stub
        for(int i=0;i<size;i++){
            if(field==cu_field[i]){
                final int k=i;
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        Dialog.alert("You click on Item No "+k);
                    }
                });
            }
        }
    }
}

class CustomListField extends HorizontalFieldManager{

    private Bitmap scale_image;
    private int width=0;
    private int height=0;
    private int background_color=0;
    private BitmapField bitmap_field;
    private boolean flag=false;
    public CustomListField(String title, Bitmap image, String date,int image_width,int image_height,int background_color){
        super(NO_HORIZONTAL_SCROLL|USE_ALL_WIDTH);
        this.background_color=background_color;
        width=image_width;
        height=image_width;
        if(image!=null){
            scale_image=new Bitmap(image_width, image_height);
            image.scaleInto(scale_image, Bitmap.FILTER_LANCZOS);
            bitmap_field=new BitmapField(scale_image);
            flag=false;
            bitmap_field.setMargin(5, 5, 5, 5);
            add(bitmap_field);
        }
       
       
        VerticalFieldManager vmanager=new VerticalFieldManager(USE_ALL_WIDTH|Field.FIELD_VCENTER){
            protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(Display.getWidth()-width, height);
                setExtent(Display.getWidth()-width, height);
            }
        };
        LabelField title_lbl=new LabelField("Title: "+title,Field.NON_FOCUSABLE|DrawStyle.ELLIPSIS);
        vmanager.add(title_lbl);
       
        LabelField date_lbl=new LabelField("Date: "+date,Field.NON_FOCUSABLE);
        vmanager.add(date_lbl);
       
        Font fon=title_lbl.getFont();
        int title_height=fon.getHeight();
       
        Font font=date_lbl.getFont();
        int date_height=font.getHeight();
        int pad=title_height+date_height;
        title_lbl.setPadding((height-pad)/2, 0, 0, 0);
        add(vmanager);
        add(new NullField(FOCUSABLE));
    }
   
    protected void sublayout(int maxWidth, int maxHeight) {
        super.sublayout(Display.getWidth(), height);
        setExtent(Display.getWidth(), height);
    }
    protected void paint(Graphics graphics) {
        if(flag)
        graphics.setBackgroundColor(background_color);
        graphics.clear();
        super.paint(graphics);
    }
    protected void onFocus(int direction) {
        super.onFocus(direction);
        flag=true;
        invalidate();
    }
    protected void onUnfocus() {
        invalidate();
        flag=false;
    }
    protected boolean navigationClick(int status, int time) {
       
        if(Touchscreen.isSupported()){
            return false;
        }else{
            fieldChangeNotify(1);
            return true;
        }
       
    }
    protected boolean touchEvent(TouchEvent message)
    {
        if (TouchEvent.CLICK == message.getEvent())
        {
           
            FieldChangeListener listener = getChangeListener();
            if (null != listener)
                this.setFocus();
                listener.fieldChanged(this, 1);
        }
        return super.touchEvent(message);
    }
}