Blackberry BrowserField2 extreemly slow loading times - blackberry

I am currently trying to load some pages with a BrowserField2 but the loading time takes way to long. Loading the same page in the OS Browser works fine (<5 sec) but loading it within my app takes >30 seconds. What could be the reason? Here is my code:
BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER);
config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);
browserField = new BrowserField(config);
BrowserFieldListener listener = new BrowserFieldListener() {
public void documentCreated(BrowserField browserField, ScriptEngine scriptEngine, Document document) throws Exception{
// Show a loadinganimation
}
public void documentLoaded(BrowserField browserField, Document document) throws Exception{
try{
// Hide a loadingAnimation
}catch(IllegalStateException es){
es.printStackTrace();
}
}
};
browserField.addListener( listener );
I had the same problem before I implemented the BrowserFieldListener (and loading animation) so it has nothing to do with that. Have I missed something?

Related

How to navigate to a different content page after a function is called

I have an app that has 2 tabs in Xamarin forms (iOS side). I'd like to know how to make my app navigate to a different content page after a function is called. Let me show you what I mean in code:
these are my two functions in my content page:
protected override async void OnAppearing()
{
base.OnAppearing();
TakePhotoButton_Clicked();
}
async void TakePhotoButton_Clicked()
{
if (App.pictureTaken) return;
App.pictureTaken = true;
//Allows users to take pictures in the app
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
DisplayAlert("No Camera", "Camera is not available.", "OK");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
//Sets the properties of the photo file
SaveToAlbum = true,
PhotoSize = PhotoSize.MaxWidthHeight,
DefaultCamera = CameraDevice.Rear
});
if (file == null)
return;
}
After calling the TakePhotoButton_Clicked() I'd like to force my app to navigate to my other content page.
in pseudocode it would look like:
NavigateTo(MyOtherContentPage);
But im not sure how that would work or if something like that exists. Any suggestions?
Welcome to SO!
If Root page of MainPage is NavigationPage , such as: MainPage = new NavigationPage (new Page1Xaml ()); , you can use Navigation.PushAsync to navigate to another page as follow :
async void OnNextPageButtonClicked (object sender, EventArgs e)
{
await Navigation.PushAsync (new Page2Xaml ());
}
Else if Root page is a normal Page, you can use model naivgation method to navigate to another page as follow:
async void OnItemSelected (object sender, SelectedItemChangedEventArgs e)
{
...
await Navigation.PushModalAsync (detailPage);
}
}
More info can refer to Performing Navigation and Pushing Pages to the Modal Stack.

Autodetect proxy - JavaFX - webview

My browser (webview) starts with an HTML page
FILEJAVA.class.getResource ("FILEHTML.html"). ToExternalForm ()
Whenever I access the google, I want to know whether the browser check, if the network has proxy (proxy'm working manual)
So that the browser shows a dialog to enter User name and password.
You can use ProxySelector to check proxy. See next example:
public class DetectProxy extends Application {
private Pane root;
#Override
public void start(final Stage stage) throws URISyntaxException {
root = new VBox();
List<Proxy> proxies = ProxySelector.getDefault().select(new URI("http://google.com"));
final Proxy proxy = proxies.get(0); // ignoring multiple proxies to simplify code snippet
if (proxy.type() != Proxy.Type.DIRECT) {
// you can change that to dialog using separate Stage
final TextField login = new TextField("login");
final PasswordField pwd = new PasswordField();
Button btn = new Button("Submit");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
System.setProperty("http.proxyUser", login.getText());
System.setProperty("http.proxyPassword", pwd.getText());
showWebView();
}
});
root.getChildren().addAll(login, pwd, btn);
} else {
showWebView();
}
stage.setScene(new Scene(root, 600, 600));
stage.show();
}
private void showWebView() {
root.getChildren().clear();
WebView webView = new WebView();
final WebEngine webEngine = webView.getEngine();
root.getChildren().addAll(webView);
webEngine.load("http://google.com");
}
public static void main(String[] args) {
launch();
}
}
authentification may require additional code in some cases, see Authenticated HTTP proxy with Java for details.

Vaadin cropfield selection stick to top

In vaadin application I use CropField addon to crop user's avatar. The problem is that whenever I try to test it, selection area is always stick to the top of the cropfield. Everything was fine on one page but when I copied exactly that piece of code to another page the problem has occured. Do you have any ideas why?
NativeButton nb = new NativeButton("Click on me");
layout.addComponent(nb);
nb.addListener(new ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
final Window window = new Window();
window.setModal(true);
DivLayout cropContent = new DivLayout();
window.setContent(cropContent);
final CropField cropField = new CropField(new ExternalResource("http://upload.wikimedia.org/wikipedia/commons/1/1e/Stonehenge.jpg"));
cropField.setSelectionAspectRatio(1);
cropContent.addComponent(cropField);
//cropField.setImmediate(true);
NativeButton btClose = new NativeButton("Close");
btClose.addListener(new ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
getMyApplication().getMainWindow().removeWindow(window);
}
});
cropContent.addComponent(btClose);
getMyApplication().getMainWindow().addWindow(window);
}
});

Integration of twitter posting in Blackberry+IllegalArguementException

i am trying to embed twitter posting feature in my application.
i am using twitter api_me-1.8
i am able to reach the login screen(though most of the text is displayed as boxes- i am guessing that the text is in hindi/tamil as i am in india...), but as soon as i enter my credentials,i get taken to another page with some text in the top in boxes...
and more text in english below that(you can revoke access to any application...) ...then i get an illeagalArguementException after a minute...
i tried to debug the application,
public TwitterUiScreen(String wallMsg) {
System.out.println("Twitter UI BEGINS!");
setTitle("Twitter");
this.wallMsg = wallMsg;
BrowserContentManager browserMngr = new BrowserContentManager(0);
RenderingOptions rendOptions = browserMngr.getRenderingSession()
.getRenderingOptions();
rendOptions.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.SHOW_IMAGES_IN_HTML, false);
rendOptions.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.ENABLE_EMBEDDED_RICH_CONTENT, true);
rendOptions.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.DEFAULT_FONT_FACE, true);
rendOptions.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.DEFAULT_CHARSET_VALUE, true);
rendOptions.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.JAVASCRIPT_ENABLED, true);
/*
* browserMngr.getRenderingSession().getRenderingOptions().setProperty(
* RenderingOptions.CORE_OPTIONS_GUID,
* RenderingOptions.DEFAULT_FONT_FACE, Font.getDefaultFont());
*/
add(browserMngr);
OAuthDialogWrapper pageWrapper = new BrowserContentManagerOAuthDialogWrapper(browserMngr);
pageWrapper.setConsumerKey(CONSUMER_KEY);
pageWrapper.setConsumerSecret(CONSUMER_SECRET);
pageWrapper.setCallbackUrl(CALLBACK_URL);
pageWrapper.setOAuthListener(this);
pageWrapper.login();
}
i had breakpoints upto the last line, and all of them were hit, with no problems...
but as soon as i logged in, i hit the exception.( i think it was in this page:-
BrowserContentManagerOAuthDialogWrapper.java (version 1.1 : 45.3, super bit)
after which i get to a third screen.
the comment was barely legible- so i thought i might as well add the code over here:
public static final String OAUTH_CALLBACK_SCHEME = "x-oauthflow-twitter";
public static final String OAUTH_CALLBACK_HOST = "callback";
public static final String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME+ "://" + OAUTH_CALLBACK_HOST;
private final String CALLBACK_URL = OAUTH_CALLBACK_URL;
i managed to get the source and attach it to the jar file. the exception that the BrowserContentManagerOAuthDialogWrapper.java throws is:: Protocol not found: net.rim.device.cldc.io.x-oauthflow-twitter.Protocol
in this method::
protected void loadUrl(final String url, final byte[] postData,
final Event event) {
new Thread() {
public void run() {
try {
HttpConnection conn = getConnection(url);
//
if (postData != null) {
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty(
"Content-Type",
"application/x-www-form-urlencoded");
conn.setRequestProperty(
"Content-Length", String.valueOf(postData.length));
//
OutputStream out = conn.openOutputStream();
out.write(postData);
out.close();
}
//
browserManager.setContent(
conn, renderingListenerOAuth, event);
} catch (IOException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
}.start();
}
feel like hitting myself.
my clients had told us that the twitter posting was not working...
so i assumed that it did not work.
for some reason, it does not work in the simulator- but seems to work fine on the device.
the clients have assumed that it does not work, as after we try logging in, it takes too long to post, and displays the third screen for about 20 seconds, and they seem to have clicked back early, deciding that posting did not work.
now i need to figure out a way to post a message on the third screen asking the user to wait for the post to be successful.

HTTPS page not loaded on BrowserContent

I am implementing an embedded browser in my app, and because it has to be compatible with OS 4.0, BrowserContent is my only choice.
When opening a HTTPS page the screen is blank, but this problem doesn't occur when a BrowserSession is used. So I put a println after the BrowserContent part, and it doesn't show up in the console output. So I think this is something wrong with that.
class BrowserScreen extends MainScreen {
private RenderingSession _renderingSession;
private HttpsConnection _connection;
public BrowserScreen(String url) {
_renderingSession = RenderingSession.getNewInstance();
final String _url = url;
new Thread() {
public void run() {
try {
_connection =
(HttpsConnection)Connector.open(_url, Connector.READ, true);
BrowserContent content =
_renderingSession.getBrowserContent(_connection, null, 0);
content.finishLoading();
Field field = content.getDisplayableContent();
synchronized (UiApplication.getEventLock()) {
add(field);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
}
There is a bug in the sample, and the BB people have done nothing in this regards for years.. You will never know that your page is not rendered and you will be redirected to the calling page all by itself. When they are unable to render the page they insert a redirection code in the HTTP response instead of giving a render exception (check it out in the inputstream and convert it into string and you shall know), and the intended page is never shown. They have resolved this in 5.0 and higher using BrowserField, but we need solution for the low end mobiles.

Resources