BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 01-11-2007, 04:02 AM   #1
balaji6969
Knows Where the Search Button Is
 
Join Date: Dec 2006
Model: 8700
Carrier: airtel
Posts: 31
Thumbs down Display web contents in a field

Please Login to Remove!

hi
I want to create a screen having a field for displaying web contents.Means that field should display the page of the url i passed.I am trying by using BrowserContentBaseImpl ,but it is not displaying.No error ocuured.Can any one give solution.
Regards,
Balaji.K
Offline  
Old 01-11-2007, 04:58 AM   #2
jfisher
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Default

i seem to remember there was an implementation of the browserfield in the samples of one of the jde release. i could be wrong though, it's been a while.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 01-11-2007, 06:21 AM   #3
balaji6969
Knows Where the Search Button Is
 
Join Date: Dec 2006
Model: 8700
Carrier: airtel
Posts: 31
Default

ya i hav seen it just now and its working.Thanks for ur suggestion.

Regards,
Balaji.K
Offline  
Old 01-12-2007, 12:10 PM   #4
EZboy
New Member
 
Join Date: Dec 2006
Model: 8700
Posts: 13
Default

Can somebody post the code for that demo, i cant find it in the JDE samples.
Thanks.
Offline  
Old 01-12-2007, 12:22 PM   #5
EZboy
New Member
 
Join Date: Dec 2006
Model: 8700
Posts: 13
Default

Dont mind, found it!

Code:
/*
 * BrowserFieldSampleApplication.java
 *
 * Copyright ¬ 1998-2006 Research In Motion Ltd.
 */

package com.rim.samples.device.blackberry.browser;

import java.io.IOException;

import javax.microedition.io.HttpConnection;

import net.rim.device.api.browser.field.*;
import net.rim.device.api.io.http.HttpHeaders;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.Status;
import net.rim.device.api.ui.container.MainScreen;

/**
 *
 */
final public class BrowserFieldSampleApplication extends UiApplication implements RenderingApplication {
   
    private static final String REFERER = "referer";  
   
    private RenderingSession _renderingSession;  

    private MainScreen _mainScreen;
   
    private HttpConnection  _currentConnection;
   
    /***************************************************************************
     * Main.
     **************************************************************************/
    public static void main(String[] args) {
        BrowserFieldSampleApplication app = new BrowserFieldSampleApplication();
        app.enterEventDispatcher();
    }
   
    private BrowserFieldSampleApplication() {       
       
        _mainScreen = new MainScreen();       
        pushScreen(_mainScreen);
        _renderingSession = RenderingSession.getNewInstance();
       
        // enable javascript
        //_renderingSession.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.JAVASCRIPT_ENABLED, true);                       

       
        PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread("http://www.google.com", null, null, null, this);

        thread.start();                      
            
    }
         
    public void processConnection(HttpConnection connection, Event e) {
        
        // cancel previous request
        if (_currentConnection != null) {
            try {
                _currentConnection.close();
            } catch (IOException e1) {
            }
        }
       
        _currentConnection = connection;
       
        BrowserContent browserContent = null;
       
        try {
            browserContent = _renderingSession.getBrowserContent(connection, this, e);
           
            if (browserContent != null) {
               
                Field field = browserContent.getDisplayableContent();
               
                if (field != null) {
                    synchronized (Application.getEventLock()) {
                        _mainScreen.deleteAll();
                        _mainScreen.add(field);
                    }
                }
               
                browserContent.finishLoading();
            }
                                                        
        } catch (RenderingException re) {

        } finally {
            SecondaryResourceFetchThread.doneAddingImages();
        }
       
    }

    /**
     * @see net.rim.device.api.browser.RenderingApplication#eventOccurred(net.rim.device.api.browser.Event)
     */
    public Object eventOccurred(Event event) {

        int eventId = event.getUID();

        switch (eventId) {

            case Event.EVENT_URL_REQUESTED : {

                UrlRequestedEvent urlRequestedEvent = (UrlRequestedEvent) event;   
                String absoluteUrl = urlRequestedEvent.getURL();
   
                HttpConnection conn = null;
                PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(urlRequestedEvent.getURL(),
                                                                                         urlRequestedEvent.getHeaders(),

                                                                                         urlRequestedEvent.getPostData(),

                                                                                         event, this);
                thread.start();
   
                break;

            } case Event.EVENT_BROWSER_CONTENT_CHANGED: {               
                   
                // browser field title might have changed update title
                BrowserContentChangedEvent browserContentChangedEvent = (BrowserContentChangedEvent) event;
           
                if (browserContentChangedEvent.getSource() instanceof BrowserContent) {
                    BrowserContent browserField = (BrowserContent) browserContentChangedEvent.getSource();
                    String newTitle = browserField.getTitle();
                    if (newTitle != null) {
                        _mainScreen.setTitle(newTitle);
                    }
                }                  

                break;               

            } case Event.EVENT_REDIRECT : {

                    RedirectEvent e = (RedirectEvent) event;
                    String referrer = e.getSourceURL();
                                       
                    switch (e.getType()) {

                        case RedirectEvent.TYPE_SINGLE_FRAME_REDIRECT :
                            // show redirect message
                            Application.getApplication().invokeAndWait(new Runnable() {
                                public void run() {
                                    Status.show("You are being redirected to a different page...");
                                }
                            });

                            break;

                        case RedirectEvent.TYPE_JAVASCRIPT :
                            break;
                        case RedirectEvent.TYPE_META :
                            // MSIE and Mozilla don't send a Referer for META Refresh.
                            referrer = null;    
                            break;
                        case RedirectEvent.TYPE_300_REDIRECT :
                            // MSIE, Mozilla, and Opera all send the original
                            // request's Referer as the Referer for the new
                            // request.
                            Object eventSource = e.getSource();
                            if (eventSource instanceof HttpConnection) {
                                referrer = ((HttpConnection)eventSource).getRequestProperty(REFERER);
                            }
                            break;

                    }
                   
                    HttpHeaders requestHeaders = new HttpHeaders();
                    requestHeaders.setProperty(REFERER, referrer);
                    PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(e.getLocation(), requestHeaders,null, event, this);

                    thread.start();
                    break;

            } case Event.EVENT_CLOSE :
                // TODO: close the appication
                break;
           
            case Event.EVENT_SET_HEADER :        // no cache support
            case Event.EVENT_SET_HTTP_COOKIE :   // no cookie support
            case Event.EVENT_HISTORY :           // no history support           
            case Event.EVENT_EXECUTING_SCRIPT :  // no progress bar is supported
            case Event.EVENT_FULL_WINDOW :       // no full window support
            case Event.EVENT_STOP :              // no stop loading support
            default :
        }

        return null;
    }

    /**
     * @see net.rim.device.api.browser.RenderingApplication#getAvailableHeight(net.rim.device.api.browser.BrowserContent)

     */
    public int getAvailableHeight(BrowserContent browserField) {
        // field has full screen
        return Graphics.getScreenHeight();
    }

    /**
     * @see net.rim.device.api.browser.RenderingApplication#getAvailableWidth(net.rim.device.api.browser.BrowserContent)

     */
    public int getAvailableWidth(BrowserContent browserField) {
        // field has full screen
        return Graphics.getScreenWidth();
    }

    /**
     * @see net.rim.device.api.browser.RenderingApplication#getHistoryPosition(net.rim.device.api.browser.BrowserContent)

     */
    public int getHistoryPosition(BrowserContent browserField) {
        // no history support
        return 0;
    }

    /**
     * @see net.rim.device.api.browser.RenderingApplication#getHTTPCookie(java.lang.String)
     */
    public String getHTTPCookie(String url) {
        // no cookie support
        return null;
    }

    /**
     * @see net.rim.device.api.browser.RenderingApplication#getResource(net.rim.device.api.browser.RequestedResource,
     *      net.rim.device.api.browser.BrowserContent)
     */
    public HttpConnection getResource( RequestedResource resource, BrowserContent referrer) {

        if (resource == null) {
            return null;
        }

        // check if this is cache-only request
        if (resource.isCacheOnly()) {
            // no cache support
            return null;
        }

        String url = resource.getUrl();

        if (url == null) {
            return null;
        }

        // if referrer is null we must return the connection
        if (referrer == null) {
            HttpConnection connection = Utilities.makeConnection(resource.getUrl(), resource.getRequestHeaders(), null);

            return connection;
           
        } else {
           
            // if referrer is provided we can set up the connection on a separate thread
            SecondaryResourceFetchThread.enqueue(resource, referrer);
           
        }

        return null;
    }

    /**
     * @see net.rim.device.api.browser.RenderingApplication#invokeRunnable(java.lang.Runnable)
     */
    public void invokeRunnable(Runnable runnable) {
        (new Thread(runnable)).run();
    }
   
}

class PrimaryResourceFetchThread extends Thread {
   
    private BrowserFieldSampleApplication _application;
   
    private Event _event;

    private byte[] _postData;

    private HttpHeaders _requestHeaders;

    private String _url;
   
    PrimaryResourceFetchThread(String url, HttpHeaders requestHeaders, byte[] postData,
                                  Event event, BrowserFieldSampleApplication application) {
       
        _url = url;
        _requestHeaders = requestHeaders;
        _postData = postData;
        _application = application;
        _event = event;
    }

    public void run() {
        HttpConnection connection = Utilities.makeConnection(_url, _requestHeaders, _postData);
        _application.processConnection(connection, _event);       
    }
}
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Vacuum Air Fuel Water Line Tube Hose Barbed Connector Coupling Tee Elbow T X Y picture

Vacuum Air Fuel Water Line Tube Hose Barbed Connector Coupling Tee Elbow T X Y

$1.99



Bissell 3-in-1 Lightweight Corded Stick Vacuum 2030 picture

Bissell 3-in-1 Lightweight Corded Stick Vacuum 2030

$28.88



BISSELL 3-in-1 Turbo Lightweight Stick Vacuum, 2610 (Black) picture

BISSELL 3-in-1 Turbo Lightweight Stick Vacuum, 2610 (Black)

$37.96



Shark RV761_N Robotic Vacuum Cleaner With Charging Dock Navy Blue Black Tested picture

Shark RV761_N Robotic Vacuum Cleaner With Charging Dock Navy Blue Black Tested

$38.00



3 CFM Air Vacuum Pump HVAC Manifold Gauge Set AC A/C Refrigeration Kit picture

3 CFM Air Vacuum Pump HVAC Manifold Gauge Set AC A/C Refrigeration Kit

$47.55



VEVOR 5 Gallon Vacuum Chamber with 5CFM Vacuum Pump Kit 1/3HP Single Stage 110V picture

VEVOR 5 Gallon Vacuum Chamber with 5CFM Vacuum Pump Kit 1/3HP Single Stage 110V

$104.99







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.