I am using a QR code scan library zxing.
Is there a way to use multiple bar code formats at the same time?
EXAMPLE)
ONE_D_CODE_TYPES And DATA_MATRIX
ScanOptions options = new ScanOptions();
//like this
options.setDesiredBarcodeFormats(ScanOptions.ONE_D_CODE_TYPES);
options.setDesiredBarcodeFormats(ScanOptions.DATA_MATRIX);
options.setPrompt("Scan a barcode");
options.setCameraId(0); // Use a specific camera of the device
options.setBeepEnabled(false);
options.setBarcodeImageEnabled(true);
You can use both of them using | character. Try this to use both of them:
options.setBarcodeFormats(ScanOptions.ONE_D_CODE_TYPES | ScanOptions.DATA_MATRIX);
Related
I am working on an android app where I am saving the a lock pattern.
While the user enters a pattern while powering on the screen, I am checking if it is the same as the saved pattern.
I am saving the pattern in the application using: https://github.com/haibison/android-lockpattern/
The problem is that both are in different formats:
1) lockpattern Object captured while powering on the screen:
[(row=1,clmn=0), (row=0,clmn=1), (row=1,clmn=1), (row=2,clmn=1), (row=1,clmn=2)]
2) And this one i am capturing using haibison's method:
char[] pattern = data.getCharArrayExtra(LockPatternActivity.EXTRA_PATTERN);
String lockpattern = new String(pattern);
Can you please provide some examples/links.
Should I not use haibison's method?
You have to set an Encrypter before starting the Lockpattern-Intent in order to get a proper representation from haibison's char-array , e.g. LPEncrypter (https://bitbucket.org/haibison/android-lockpattern/wiki/Encryption):
AlpSettings.Security.setEncrypterClass(context, LPEncrypter.class);
E.g. a simple representation for this pattern:
Simple Pattern
Habisons char array without the Encrypter is like this:
[3,9,7,7,c,9,3,7,e,c,e,a,5,6,2,4,0,e,a,7,3,9,3,4,b,8,e,9,a,c,9,7,6,6,e,8,e,8,d,0]
using the Example-Encrypter with
String[] ids = new String(pattern).split("[^0-9]");
you'll get [1,-,2,-,3,-,6] which should be easy to convert into your lockpattern-representation.
I'm developing a simple utility to record the screen of device using the new function of kitkat 4.4. So, I've create a button with various edit text for the parameters such as bit rate, seconds and file name. I've this code.
StringBuilder builder;
builder = new StringBuilder("system/bin/screenrecorder");
When i retrieve the parameters do something like
builder.append(" --bit-rate ").append(editText.getText());
Finally I've the complete command to record, like
"system/bin/screenrecorder --size 720x1184 --bit-rate 5 --time-limit 5 /storage/emulated/0/MyVideos/example.mp4"
My question now is this:
How can i execute this command? In other words, what should I do now to start recording using the variable builder?
I was trying to figure out what are the input languages installed on Windows from a Java application. You can manually figure this from out Control Panel->Region and Language->Change keyboards(button)->General->Installed Services(bottom panel).
The background is that in the application I am forcing Locale.US using a following call -
Component component = getAWTComponent();
component.getInputContext().selectInputMethod(Locale.US)
But on some hosts US keyboard language is not installed (say a system in UK). I wanted to verify that the language is not available and throw an error or something.
Also, is it possible to install such services from Java (far-fetched may be..)?
Messing with the default keyboard layout is something that should only be done with great care. If you do this at all, you should give users an option to select which layout they want instead of forcing a certain layout on everyone.
Imagine your reaction if I wrote an app and tried to force you to use the German keyboard.
That said, the API will fall back to a valid keyboard layout when Locale.US isn't available. The code which does that is hidden in sun.awt.im.InputContext.selectInputMethod()
Using reflection, you should be able to replicate the part of the code which checks whether some locale is supported.
static public void main(String[]args) {
Locale al[] = DateFormat.getAvailableLocales();
for (Locale l : al) {
System.out.println(l);
}
}
Java can found your default charset :
public final static Charset CHARSET_SYSTEM =
Charset.forName(System.getProperties().get("sun.jnu.encoding").toString());
then you can use it in a Scanner to transform input charset in UniCode :
Scanner scan = null;
final void defineScan(Charset charsetCanBeNull) {
scan = new Scanner(System.in, (null == charsetCanBeNull)
? charset
: charsetCanBeNull);
}
Then you can use Scanner.methods(..)
I am trying to render and export FusionCharts completely on the server. I am aware of solutions such as FCimg and FusionCharts .NET Solution. I have also implemented a Java solution that uses the Process class to run wkhtmltoimage.
However, I am trying to find a pure Java solution of doing this. I have an html file that includes FusionCharts JS Libraries and code to generate the fusion chart. I found JxBrowser that properly renders the chart but it requires X-Server for it to work on Linux. I also have tried Cobra/Lobo Browser but it does not fully support JavaScript. Are there any other ways to render and export fusion charts on the server or atleast render an html file that includes JavaScript completely in Java (and that does not require xserver)?
Thanks in advance for all the help!
Update: Solution that does not require xserver: WebRenderer. The Swing Edition is the only edition that supports HTML5 as of July 9th, 2012. You can use the swing edition to capture the image without a GUI.
I found a way that uses Eclipse's SWT Browser. However this cannot be run in an headless mode. You will have to use xserver to implement this. See this question.
Since this requires xserver and cannot be run in an headless mode, I would suggest using JxBrowser. It is a lot simpler and all you need is to generate an html file with all the fusion charts scripts. See #1, #2, #3
You have to create a template.html file that contains the header
(<html><head>), jquery.min.js, FusionCharts.js,
FusionCharts.HC.js, FusionCharts.HC.Charts.js. Make sure each of
these scripts are in their own script tags (<script type="text/javascript"> [js code] </script>)
Now add another JavaScript function with its own script tags containing the steps to render the chart. For example:
function load() { FusionCharts.setCurrentRenderer('javascript'); var chart = new FusionCharts("swf", 'chart0', "width", "height", "0", "1"); chart.setXMLData("XML DATA HERE"); chart.render("divNAMEHere"); }
Now you need to call the load() function onload, create a div to render the chart in, and end the html file. For example:
`
test
`
Create a new class that imports the eclipse swt browser libraries. Instantiate Display, Shell, and Browser (use this as a guideline to help understand what is happening: http://www.roseindia.net/tutorials/swt/swt-browser.shtml).
Set the text of the browser (browser.setText("htmlcode")) to the html code from template.html. The best way to do this would be to read the file using BufferedReader.
Lastly, the image takes some time to render. Now there is probably a better way to do this but if you want to just get it working, I set up a count and it captures the image after a certain number. This is what you need to add to the end:
int i = 0;
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
i++;
// System.out.println(i);
if(i==100)
{
GC source = new GC (shell);
Image image = new Image(display, browser.getClientArea());
source.copyArea(image, 0, 0);
ImageLoader io = new ImageLoader ();
io.data = new ImageData[] { image.getImageData() };
File f = new File (currentDir+"/workpng.png");
io.save (f.getAbsolutePath(), SWT.IMAGE_PNG);
}
}
}
Can I play video using Vaadin framewotk ?
The main idea is loading video files from local drive in flv or avi formats and play it in web using vaadin framework.
Thanks.
There is a sample in the Sampler: http://demo.vaadin.com/sampler/#FlashEmbed
You can see the source by clicking 'view source', and it will show you something like this:
Embedded e = new Embedded(null, new ExternalResource(
"http://www.youtube.com/v/meXvxkn1Y_8&hl=en_US&fs=1&"));
e.setMimeType("application/x-shockwave-flash");
e.setParameter("allowFullScreen", "true");
e.setWidth("320px");
e.setHeight("265px");
addComponent(e);
Obviously, you'll want to change the ExternalResource to something else (e.g FileResource, ClassResource, StreamResource, ...) in order to play local files.
Vaadin version 6.7 brought a new class Video that uses the new HTML5 "video" element to embed video on a page.
My posting on the Vaadin Forum provides the source code for an example app.
The main part of that code, when populating a window or layout:
Video v = new Video( "video" ); // Instantiate video player widget.
// Specify a list of your video in one or more formats.
// Different browsers support various different video formats.
v.setSources(
new ExternalResource( "http://www.example.com/media/example_video.mp4" ),
new ExternalResource( "http://www.example.com/media/example_video.ogv" )
);
v.setWidth( "640px" ); // Set size of the video player's display area on-screen.
v.setHeight( "360px" );
this.addComponent( v ); // Add the component to the window or layout.
Oops, I just re-read you posting -- you want to play local video files. Do you mean local to the user's computer or the Vaadin app server-side computer? Either way, you may be able to manipulate the "ExternalResource" seen above, or another subclass of Vaadin Resource to access a local file.
You can use the Embedded Class to embed videos.
NOTE: This is for local files:
FileResource fileResource = new FileResource(new File("/Users/user/Downloads/DBTI_1991_teaser_HD.mp4"));
Video vd = new Video();
vd.setAutoplay(true);
vd.setSource(fileResource);
this.addComponent(vd);
Another alternative is the Vaadin add-on "YouTubePlayer" if you want to access a video specifically from YouTube.com.