Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 88
Registered: ‎09-25-2008
My Device: Not Specified
Accepted Solution

"Charging" Tip when loading a bitmap.

Hi,

 

Im developing an app that uses google maps static API. The app gets imgs from google maps and it takes its time.

 

How can I draw a "Chargin..." tip while an img is being download?

 

I've tried some ideas but I think that the UI is painted by another thread and it doesnt work.

 

Thanks!

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: "Charging" Tip when loading a bitmap.

See UiApplication.invokeLater()

 

Developer
Posts: 88
Registered: ‎09-25-2008
My Device: Not Specified

Re: "Charging" Tip when loading a bitmap.

Any sample code, please?

 

Thanks!

Developer
Posts: 88
Registered: ‎09-25-2008
My Device: Not Specified

Re: "Charging" Tip when loading a bitmap.

I've proved several ideas and this is working:

 

    private void updateMap(){
       
        try {

            cargando = true;
           
            UiApplication.getUiApplication().repaint();       
            Bitmap img = gmap.getMap();           
            imgField.setBitmap(img);
            cargando = false;
            GoogleMapsScreen.this.invalidate();
           
        } catch (Exception e) {
            Dialog.inform("Error al obtener la imagen: " + e.getMessage());
        }
       
    }   

    protected void paint(Graphics graphics) {
        super.paint(graphics);
        if(cargando){
            int color = graphics.getColor();
            graphics.setColor(Color.BLUE);
            graphics.drawText("Cargando...", 10, Display.getHeight() - 50);
            graphics.setColor(color);           
        }
           
    }

Developer
Posts: 49
Registered: ‎08-25-2009
My Device: Not Specified

Re: "Charging" Tip when loading a bitmap.

Hii sickned,

 

I am developing an app which required the position of the user and  blackberry map is not available for every location. so,

can you give me the code for implementing the google static maps in blackberry.

 

Thanks 

shashank

Highlighted
Developer
Posts: 49
Registered: ‎08-25-2009
My Device: Not Specified

Re: "Charging" Tip when loading a bitmap.

This is how we can get static map from google.

 

 

 

	public void staticMaps(double latitude, double longitude) {
		InputStream iStream;
		PNGEncodedImage Map;
		BitmapField myLocation;
		int width = Const.width;
		int height = Const.height;

		HttpConnection httpConnection = null;
		String iurl = "http://maps.google.com/maps/api/staticmap?center="
				+ latitude + "," + longitude + "&zoom=14" + "&size=" + width
				+ "x" + height + "&maptype=roadmap"
				+ "&markers=color:blue|label:L|" + latitude + "," + longitude
				+ "&sensor=false&key=YOURKEY";

		try {
			httpConnection = (HttpConnection) Connector.open(iurl);

			httpConnection.setRequestMethod(HttpConnection.GET);

			if (httpConnection.getResponseCode() == HttpConnection.HTTP_OK) {

				iStream = httpConnection.openInputStream();

				ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

				byte[] buffer = new byte[256];
				int len = 0, imageSize = 0;

				while (-1 != (len = iStream.read(buffer))) {
					byteArrayOutputStream.write(buffer);
					imageSize += len;
				}

				byteArrayOutputStream.flush();
				byte[] imageData = byteArrayOutputStream.toByteArray();

				iStream.close();
				byteArrayOutputStream.close();
				httpConnection.close();

				Map = (PNGEncodedImage) PNGEncodedImage
						.createEncodedImage(imageData, 0, imageSize);

				myLocation.setImage(googleMap);

				add(myLocation);
			}

		} catch (Exception e) {
		}
	}