How to generate qrcode in codename one - codenameone

I'm trying to generate qrcode code in my application with qrgen and then saved in specific file but there is a problem in the libary 'java.io.FileOutputStream' where it can not be found. i want to know how to replace the libary and if there is another way to generate qrcode please share it with me
ByteArrayOutputStream out =QRCode.from(s).to(ImageType.PNG).stream();
try {
FileOutputStream fout = new FileOutputStream(new File(
"C:\\Users\\Public\\Pictures\\Sample Pictures\\QR_Code.JPG"));
fout.write(out.toByteArray());
fout.flush();
fout.close();
} catch (Exception e) {
// Do Logging
}

That isn't supported. Mobile devices don't have a file system in the way desktops have so this logic just won't work. There is a file system but it's to a large part private to the application, see: https://www.codenameone.com/manual/files-storage-networking.html

Related

zipme implementation in codenameone

I want to apply unzipping the file using zipme cn1 library (codenameone library). Is there any examples on how to do it? Can anyone give me the starting point? So far I have tried the following code but I am not sure where to keep dataName.zip file in the project and the folder to keep all the files after unzipping.
#Override
protected void beforeMain(Form f) {
net.sf.zipme.ZipEntry dataZE;
InputStream isData = getClass().getResourceAsStream("/" + "dataName" + ".zip");
StringBuffer sbData = new StringBuffer();
ZipInputStream dataZIS = new ZipInputStream(isData);
try {
while ((dataZE = dataZIS.getNextEntry()) != null) {
//how to extract the zip file in a separate folder...
dataZIS.closeEntry();
}
} catch (IOException ex) {
System.out.println("zip exception");
}
}
The above code gives following error:
cannot find symbol
InputStream isData = getClass().getResourceAsStream("");
symbol: method getResourceAsStream(String)
One more thing, why cant I use the following to get the zip file as in core java
ZipInputStream zis = new ZipInputStream(new FileInputStream("C:\\abc.zip"));
// it gives "FileInputStream: cannot find symbol"
How can I extract the zip file in a separate folder?
You should use Display.getInstance().getResourceAsStream().
FileInputStream isn't supported in Codename One which uses FileSystemStorage. The FileInputStream and File API's assume many things about the underlying OS that aren't always true.

How to click on captured image using sikuli

I am new to Sikuli. I am Automating a web application that have option to upload a file.
When I click on upload button it opens a popup window.In that window I have to select a file. How I can do it using sikuli.
I am using linux operating system so I can't use AutoIT.
Below is my code which I am trying
public static void imageClick()
{
Screen s= new Screen();
try {
s.capture();
s.find("Desktop.png");
s.click("Desktop.png",0);
System.out.println("Desktop is selected");
} catch (FindFailed e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Desktop.png is a image file which I kept in my project. first I am searching it then clicking on it.
Anyone can help me how I can achieve this. Any help will be highly appreciated.
Finally I done in in below way
First import sikuli jar file to your project
Capture the Image where you want to click and save it to some location
for Ex. /home/dev/Desktop/abc.png
Screen s = new Screen(); //Created the Object of screen class
s.click("/home/dev/Desktop/abc.png");
public static void imageClick()
{
Screen s= new Screen();
Pattern DesktpIcon = new Pattern("Desktop.png");
s.click(DesktpIcon);
System.out.println("Desktop is Clicked.");
}

Windows Forms OpenFileDialog and LibVLC plugins dll entry point error

I'm using libvlc library. And it works well when I play the video file, that I have chosen in openFileDialog previously. But my goal is streaming video from webcam and previewing it.
I made libvlc show webcam video on the screen, but when i commented out the openFileDialog.Show() line (that I don't need anymore), "Entry point couldn't be found in the library" error dialogs started poping out for every libvlc plugin (that is basicaly a .dll file).
private void btPlay_Click(object sender, EventArgs e)
{
/*
if (openFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
* */
CleanUp();
string pluginPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins");
string[] args = new string[]{
"--no-qt-error-dialogs",
"--ignore-config",
"--quiet",
"--plugin-path=" + pluginPath
};
//LibVlc initialization, that is where ERORR OCCURES
vlcInst = new VlcInstance(args);
/* Input media settings */
//VlcMedia media = new VlcMedia(vlcInst, openFileDialog1.FileName);
VlcMedia media = new VlcMedia(vlcInst, "dshow://");
LibVlc.libvlc_media_add_option(media.handle, "dshow-vdev=USB2.0 UVC VGA WebCam");
LibVlc.libvlc_media_add_option(media.handle, "dshow-adev=none");
/* Output media settings */
string[] outputOptions = new string[] {
"sout=#duplicate{",
"dst=",
"display",
",",
"dst=",
"'",
"transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100}",
":http{mux=ffmpeg{mux=flv},dst=:666/}",
"'",
"}"
};
LibVlc.libvlc_media_add_option(media.handle, String.Concat(outputOptions));
streamer = new VlcStreamer(media);
media.Dispose();
streamer.Drawable = mediaPanel.Handle;
streamer.Play();
}
private void CleanUp()
{
if (streamer != null)
{
streamer.Stop();
streamer.Dispose();
}
}
I can't see any relations between OpenFileDialog and libvlc plugins.
What can cause such a problem?
EDITED:
After I skip all error dialogs, program continues working.
When I was using VLC player, it made duplicates of the plugins in "plugin" folder. In my app I used those plugins and was getting errors. After I downloaded and unpacked new instance of the player, I discovered that there were no duplicates of the plugins, so I made a conclusion that the player makes copies of plugins when you launch it first time (didn't test it).
When I replaced my plugin folder with new one, all the errors were gone.

Silverlight: Business Application Needs Access To Files To Print and Move

I have the following requirement for a business application:
(All of this could be on local or server)
Allow user to select folder location
Show contents of folder
Print selected items from folder (*.pdf)
Display which files have been printed
Potentially move printed files to new location (sub-folder of printed)
How can I make this happen in Silverlight?
Kind regards,
ribald
First of all, all but the last item can be done (the way you expect). Due to security protocols, silverlight cannot access the user's drive and manipulate it. The closest you can get is accessing silverlight's application storage which will be of no help to you whatsoever in this case. I will highlight how to do the first 4 items.
Allow user to select folder location & Show contents of folder
public void OnSelectPDF(object sender)
{
//create the open file dialog
OpenFileDialog ofg = new OpenFileDialog();
//filter to show only pdf files
ofg.Filter = "PDF Files|*.pdf";
ofg.ShowDialog();
byte[] _import_file = new byte[0];
//once a file is selected proceed
if (!object.ReferenceEquals(ofg.File, null))
{
try
{
fs = ofg.File.OpenRead();
_import_file = new byte[fs.Length];
fs.Read(_import_file, 0, (int)fs.Length);
}
catch (Exception ex)
{
}
finally
{
if (!object.ReferenceEquals(fs, null))
fs.Close();
}
//do stuff with file - such as upload the file to the server
};
}
If you noticed, in my example, once the file is retrieved, i suggest uploading it to a webserver or somewhere with temporary public access. I would recommend doing this via a web service. E.g
//configure the system file (customn class)
TSystemFile objFile = new TNetworkFile().Initialize();
//get the file description from the Open File Dialog (ofg)
objFile.Description = ofg.File.Extension.Contains(".") ? ofg.File.Extension : "." + ofg.File.Extension;
objFile.FileData = _import_file;
objFile.FileName = ofg.File.Name;
//upload the file
MasterService.ToolingInterface.UploadTemporaryFileAsync(objFile);
Once this file is uploaded, on the async result, most likely returning the temporary file name and upload location, I would foward the call to some javascript method in the browser for it to use the generic "download.aspx?fileName=givenFileName" technique to force a download on the users system which would take care of both saving to a new location and printing. Which is what your are seeking.
Example of the javascript technique (remember to include System.Windows.Browser):
public void OnInvokeDownload(string _destination)
{
//call the browser method/jquery method
//(I use constants to centralize the names of the respective browser methods)
try
{
HtmlWindow window = HtmlPage.Window;
//where BM_INVOKE_DOWNLOAD is something like "invokeDownload"
window.Invoke(Constants.TBrowserMethods.BM_INVOKE_DOWNLOAD, new object[] { _destination});
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
}
Ensure you have the javascript method existing either in an included javaScript file or in the same hosting page as your silverlight app. E.g:
function invokeDownload(_destination) {
//some fancy jquery or just the traditional document.location change here
//open a popup window to http://www.myurl.com/downloads/download.aspx? fileName=_destination
}
The code for download.aspx is outside the scope of my answer, as it varies per need and would just lengthen this post (A LOT MORE). But from what I've given, it will "work" for what you're looking for, but maybe not in exactly the way you expected. However, remember that this is primarily due to silverlight restrictions. What this approach does is rather than forcing you to need a pluging to view pdf files in your app, it allows the user computer to play it's part by using the existing adobe pdf reader. In silverlight, most printing, at least to my knowledge is done my using what you call and "ImageVisual" which is a UIElement. To print a pdf directly from silverlight, you need to either be viewing that PDF in a silverlight control, or ask a web service to render the PDF as an image and then place that image in a control. Only then could you print directly. I presented this approach as a lot more clean and direct approach.
One note - with the temp directory, i would recommend doing a clean up by some timespan of the files on the server side everytime a file is being added. Saves you the work of running some task periodically to check the folder and remove old files. ;)

Silverlight file upload - file is in use by another process (Excel, Word)

all. I have a problem with uploading of the file in Silverlight application. Here is a code sample. In case when this file is opened in other application (excel or word for example) it fails to open it, otherwise it's working fine. I'm using OpenFileDialog to choose the file and pass it to this function.
private byte[] GetFileContent(FileInfo file)
{
var result = new byte[] {};
try
{
using (var fs = file.OpenRead())
{
result = new byte[file.Length];
fs.Read(result, 0, (int)file.Length);
}
}
catch (Exception e)
{
// File is in use
}
return result;
}
Is there any way i can access this file or should i just notify the user that the file is locked?
You should notify the user that the file is currently in use by another program. If another program has the file open with a lock that does allow a shared read there is no way to bypass this lock.

Resources