Codename one. Cant add webview from Gui Builder - webview

I am creating an app for IOS, I opne the theme res on the editor, add a new GUI element, and when i try to add a Web View, nothing happened, the other components like maps or similar can be added. Only happen with the Web View
There is other way??

Ok I find the way to do it on code
protected void beforeWebcams(Form f) {
WebBrowser browser=new WebBrowser();
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, browser);
}
now I will open a new question, i need to display an HTML code inside this webbrowser

Related

Printing from a Xamarin.Forms app

I'm all new to Xamarin and I'm currently working on a sample or a "prove of concept" app using Xamarin.Forms.
I'm supposed to perform a print task from this app though I'm not at this point sure what to print yet (the screen, content of a label, a file etc.).
Either way, what is the easiest way to print from a Xamarin.Forms app?
(current target is primarily Android 4.4+).
I hope this isn't too complicated :)
EDIT:
Ok let me just update this post as the original text might be a bit ambitious/vague.
I have a Xamarin.Forms project (+ an Android part) and I have some HTML available in the XF part of the project that I need to get into a WebView and print it.
From what I understand, the thing with the WebView has to be done on the Android part of the project due to the fact that this is where the printing will be handled.
I was hoping this could be done from code since I don't really need to display the WebView, just print it's content.
The Android part of the project has only the MainActivity and no layouts or XAML files.
I don't know where to add the WebView or how to access it (other than DependecyService seems to be a buzz word here) so I'm kinda stuck here.
I'm thinking that this task should be rather trivial to someone with a little more Xamarin experience than me.
Every platform XF supports has it's own mechanism for printing. XF does not provide any abstractions for printing in a cross-platform manner. You will need to write printing logic for each layer and expose it to XF using DependencyService (or some other DI engine).
Here is a good example, of course, using dependency service:
https://codemilltech.com/xamarin-forms-e-z-print/
I so wanted to do this but it was too hard. Finally built it into Forms9Patch - a MIT licensed open source project.
Verifying that Printing is available
Before printing, you should verify that printing is available on your device. To do so, call:
if (Forms9Patch.PrintService.CanPrint)
{
// do the printing here
}
Print the contents of a Xamarin.Forms.WebView
using Forms9Patch;
...
var myWebView = new Xamarin.Forms.WebView
myWebView.Source = new HtmlWebViewSource
{
Html = "some HTML text here"
};
...
myWebView.Print("my_print_job_name");
Note that your WebView does not have to be attached to a Layout. This allows you to Print without having to display the WebView in your app’s UI.
Printing an HTML string
using Forms9Patch;
...
var myHtmlString = #"
<!DOCTYPE html>
<html>
<body>
<h1>Convert to PNG</h1>
<p>This html will be converted to a PNG, PDF, or print.</p>
</body>
</html>
";
...
myHtmlString.Print("my_print_job_name");
PLEASE NOTE: iOS sometimes places the page breaks in weird places. I have a StackOverflow Bounty on why this happens and how to fix it.
Using EmbeddedResource as a source for a Xamarin.Forms.WebView
This is sort of an experimental feature I’ve built that I’ve found it useful. As such the documentation is sparse. It allow you to put HTML content in a folder in your app’s EmbeddedResources folder and then use it as a source for a WebView. A much nicer solution than using platform specific approach provided by Xamarin. It also supports putting all of the HTML content into a zip file. Please take a look at the source code to see how it works.
You can handle the printing of lists/ invoices .. with the xfinium pdf component from xamarin componentstore. With that you create your _pdffile and then call the following method which starts the adobereader from where you can select a printer (in my case google cloudprint)
public void printPdfToCloud(string _pdffile)
{
try
{
var saveto = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.ToString(), "YourApp/"+_pdffile);
string file_path = saveto;
if (System.IO.File.Exists(file_path))
{
Android.Net.Uri pdfFile = Android.Net.Uri.FromFile(new Java.IO.File(file_path));
Intent pdfIntent = new Intent(Intent.ActionView);
pdfIntent.SetPackage("com.adobe.reader");
pdfIntent.SetDataAndType(pdfFile, "application/pdf");
pdfIntent.SetFlags(ActivityFlags.NoHistory);
StartActivity(pdfIntent);
}else
{
// give a note that the file does not exist
}
}
catch (Exception E)
{
// Do some Error dialog
}
}

Facebook SDK, how to hide "Share" title on iOS?

In my Unity3D application for iOS I want to share some info in Facebook. So I have used FB.ShareLink() method in this situation.
But when it shows Share dialog there are two buttons Cancel at the left side and Share at the right side, also there is a title with "Share" text.
How can I delete or hide that "Share" title in the middle of the window?
public override void ShareLink(
Uri contentURL,
string contentTitle,
string contentDescription,
Uri photoURL,
FacebookDelegate<IShareResult> callback)
{
MethodArguments args = new MethodArguments();
args.AddUri("content_url", contentURL);
args.AddString("content_title", contentTitle);
args.AddString("content_description", contentDescription);
args.AddUri("photo_url", photoURL);
var shareLinkCall = new JavaMethodCall<IShareResult>(this, "ShareLink");
shareLinkCall.Callback = callback;
shareLinkCall.Call(args);
}
This is the code that Facebook use for sharing on Android in Facebook Unity SDK. As I see, there is no way to modify share gui from unity plugin, because all of this processes are completed in java classes.
Edit: For editing an external .jar file look at this topic:
I have an external executable jar file that I wish to edit the java files in it with Eclipse

Firefox extension convert to restartless with XBL

I'm developing a Firefox extension and need some help with it.
My extension is overlayed and uses XBL binding to add new items to the user interface.
Is it possible to convert this extension to a bootstrap type?
I'm trying to add a button to the findbar.
Used XBL to override the findbar interface.
To start with the bootstrap I included "findbar{ -moz-binding:... }" rule to the style.css and register this sheet on startup()
(with nsIStyleSheetService.loadAndRegisterSheet()).
In this case my button is added to the bar without restart.
But when I disable or remove the addon I need to restart the browser so that the button disappear.
I tried to remove it on shutdown() in the bootstrap.js using:
var fb=window.gFindBar.getElement("findbar-container")
var but=window.gFindBar.getElement("the-button")
fb.removeChild(but)
But this didn't remove it. I debugged the code and all the elements (fb, but) were found and removed but it didn't touch the real findbars in any tab I had or opened.
So I tried to unregister the stylesheet which bind my XBL to the findbar. This time the findbar just didn't open in the current tabs.
But in new tabs it opened and without the button (a little better...).
Also I've found that the findbar didn't open in the opened tabs because of a strange error:
"this.browser is undefined".
This error pointed to the findbar.xml line 533 where the code tried to run _unpdateCaseSensitivity() but it couldn't get the "gFindBar._browser" prorperty.
Maybe it's because this property wasn't loaded for the original findbar object from the browser start (it was used by the overriden findbar object)...
So this is the point I stuck on...
And the question now is:
How can I delete the button without restart and so that the findbar opens?
From the Findbar Tweak addon I extracted this method to add new checkbox to the findbar (and changed it for my needs):
var findbar=window.gFindBar
var container = findbar.getElement("findbar-container")
var button = $('<toolbarbutton>')
button.setAttribute('anonid', 'test-find-tabs')
button.setAttribute('label', 'Test')
button.setAttribute('type', 'checkbox')
button.addEventListener('command', test,false)
container.insertBefore(button, findbar.getElement('find-case-sensitive').nextSibling)
But for my final purpose it needs some additional editings. So for now I'll leave this problem. Maybe a wise thought will occur me later. Cause a good idea often comes in mind after we change the focus from the problem and then return to it...

"document" in mozilla extension js modules?

I am building Firefox extension, that creates single XMPP chat connection, that can be accessed from all tabs and windows, so I figured, that only way to to this, is to create connection in javascript module and include it on every browser window. Correct me if I am wrong...
EDIT: I am building traditional extension with xul overlays, not using sdk, and talking about those modules: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules
So I copied Strophe.js into js module. Strophe.js uses code like this:
/*_Private_ function that creates a dummy XML DOM document to serve as
* an element and text node generator.
*/
[---]
if (document.implementation.createDocument === undefined) {
doc = this._getIEXmlDom();
doc.appendChild(doc.createElement('strophe'));
} else {
doc = document.implementation
.createDocument('jabber:client', 'strophe', null);
}
and later uses doc.createElement() to create xml(or html?) nodes.
All worked fine, but in module I got error "Error: ReferenceError: document is not defined".
How to get around this?
(Larger piece of exact code: http://pastebin.com/R64gYiKC )
Use the hiddenDOMwindow
Cu.import("resource://gre/modules/Services.jsm");
var doc = Services.appShell.hiddenDOMWindow.document;
It sounds like you might not be correctly attaching your content script to the worker page. Make sure that you're using something like tabs.attach() to attach one or more content scripts to the worker page (see documentation here).
Otherwise you may need to wait for the DOM to load, waiting for the entire page to load
window.onload = function ()
{
Javascript code goes here
}
Should take at least diagnose that issue (even if the above isn't the best method to use in production). But if I had to wager, I'd say that you're not attaching the content script.

Save current webpage in Watin

I'm trying to save the full content of the current static web page, using the code from Show IE "Save As" dialog using Watin
So here it is:
IE ie = new IE("http://localhost");
// more code
//I expect out.html is the output file
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler("out.html");
//I expect this line to popup the save as dialog box, but nothing happens
ie.AddDialogHandler(fileDownloadHandler);
//the program is blocked at this line, as it can't click anywhere
ie.Link("startDownloadLinkId").Click();
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
fileDownloadHandler.WaitUntilDownloadCompleted(200);
I also tried the code below, but it doesn't save all the page:
System.IO.StreamWriter file = new System.IO.StreamWriter("output.html");
file.Write(ie.Html);
Again, I need to save the webpage from Watin, and the result to be the same as saving it manually.
Thanks!
Here is how I do it:
File.WriteAllText("myfile.html",
(myIE.InternetExplorer as SHDocVw.InternetExplorer).Document.documentElement.outerHtml);
Assumes myIE is a WatiN IE element, of course.
If you're ever having difficulty finding how to do something with WatiN, I often find it helpful to google how to do it with an "Internet Explorer COM object". WatiN wraps the object, but it is exposed and able to be accessed!
Cheers!
Try to parse the html with html agility pack and save it, there are additional abilities that you can use...
using HtmlAgilityPack;
var htmldoc = new HtmlDocument();
htmldoc.LoadHtml(ie.Html);
htmldoc.Save(stream);
Link to agility pack

Resources