On Android, Display.getInstance().openGallery() does not allow multiple selection - codenameone

The following code allows multiple image selection on iOS and the emulator. On Android the Gallery window opens but only one image can be selected - even if you long press. If you open Gallery manually (outside of the codenameone app) then multiple selection is available.
Display.getInstance().openGallery((e) -> {
if(e != null && e.getSource() != null) {
String[] files = (String[])e.getSource();
String filenames = "";
for (int i=0; i < files.length; i++) {
filenames = filenames + files[i] + "|";
}
System.out.println("selected filenames:" + filenames);
}
}, CN1Constants.GALLERY_ALL_MULTI);
A call to :
isGalleryTypeSupported(CN1Constants.GALLERY_ALL_MULTI)
returns true

This is a limitation of Androids intent system. When you pick from a gallery the first time around it should prompt you with an option to select the gallery app. Some gallery apps just don't support multi-selection.
You can clear the associations for the app from the system settings to trigger that prompt again. Then select a different application which will hopefully resolve that issue.
Unfortunately, due to the way Android works this is the only reasonable workaround.

Related

SaveFileDialog in WPF on Windows XP shows empty file list

I'm using a Microsoft.Win32.SaveFileDialog in a WPF application which is fine in Windows 10 but some users are still using Windows XP and initially the dialog shows no files.
Changing the file type to another type updates the list. It appears to only be the initial loading.
I've used System.Windows.Forms.SaveFileDialog, using a "Using", making sure the Dialog has an owner Window and using BeginInvoke on the current dispatcher.
lSaveFileDialog = new Microsoft.Win32.SaveFileDialog();
lSaveFileDialog.Title = "Datei speichern";
lSaveFileDialog.InitialDirectory = pFilenameElements.IFilenameElement_DirectoryInfo.FullName;
lSaveFileDialog.Filter = "Word Dateien (*.doc)|*.doc|Alle Dateien (*.*)|*.*";
lSaveFileDialog.RestoreDirectory = true;
lSaveFileDialog.FileName = pSuggestedFilename;
if (lSaveFileDialog.ShowDialog() == true)
{
return lSaveFileDialog.FileName;
}
I expect the Dialog to open and display other Word files in the current folder but it only does that if I switch the filter to "All" and then I see everything. Switching back to "Word" and I see the Word files.
On Windows 10 there is no problem.

WPF native windows 10 toasts

Using .NET WPF and Windows 10, is there a way to push a local toast notification onto the action center using c#? I've only seen people making custom dialogs for that but there must be a way to do it through the os.
You can use a NotifyIcon from System.Windows.Forms namespace like this:
class Test
{
private readonly NotifyIcon _notifyIcon;
public Test()
{
_notifyIcon = new NotifyIcon();
// Extracts your app's icon and uses it as notify icon
_notifyIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
// Hides the icon when the notification is closed
_notifyIcon.BalloonTipClosed += (s, e) => _notifyIcon.Visible = false;
}
public void ShowNotification()
{
_notifyIcon.Visible = true;
// Shows a notification with specified message and title
_notifyIcon.ShowBalloonTip(3000, "Title", "Message", ToolTipIcon.Info);
}
}
This should work since .NET Framework 1.1. Refer to this MSDN page for parameters of ShowBalloonTip.
As I found out, the first parameter of ShowBalloonTip (in my example that would be 3000 milliseconds) is generously ignored. Comments are appreciated ;)
I know this is an old post but I thought this might help someone that stumbles on this as I did when attempting to get Toast Notifications to work on Win 10.
This seems to be good outline to follow -
Send a local toast notification from desktop C# apps
I used that link along with this great blog post- Pop a Toast Notification in WPF using Win 10 APIs
to get my WPF app working on Win10. This is a much better solution vs the "old school" notify icon because you can add buttons to complete specific actions within your toasts even after the notification has entered the action center.
Note- the first link mentions "If you are using WiX" but it's really a requirement. You must create and install your Wix setup project before you Toasts will work. As the appUserModelId for your app needs to be registered first. The second link does not mention this unless you read my comments within it.
TIP- Once your app is installed you can verify the AppUserModelId by running this command on the run line shell:appsfolder . Make sure you are in the details view, next click View , Choose Details and ensure AppUserModeId is checked. Compare your AppUserModelId against other installed apps.
Here's a snipit of code that I used. One thing two note here, I did not install the "Notifications library" mentioned in step 7 of the first link because I prefer to use the raw XML.
private const String APP_ID = "YourCompanyName.YourAppName";
public static void CreateToast()
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(
ToastTemplateType.ToastImageAndText02);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("This is my title!!!!!!!!!!"));
stringElements[1].AppendChild(toastXml.CreateTextNode("This is my message!!!!!!!!!!!!"));
// Specify the absolute path to an image
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + #"\Your Path To File\Your Image Name.png";
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
imageElements[0].Attributes.GetNamedItem("src").NodeValue = filePath;
// Change default audio if desired - ref - https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-audio
XmlElement audio = toastXml.CreateElement("audio");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Reminder");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Mail"); // sounds like default
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Call7");
audio.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Call2");
//audio.SetAttribute("loop", "false");
// Add the audio element
toastXml.DocumentElement.AppendChild(audio);
XmlElement actions = toastXml.CreateElement("actions");
toastXml.DocumentElement.AppendChild(actions);
// Create a simple button to display on the toast
XmlElement action = toastXml.CreateElement("action");
actions.AppendChild(action);
action.SetAttribute("content", "Show details");
action.SetAttribute("arguments", "viewdetails");
// Create the toast
ToastNotification toast = new ToastNotification(toastXml);
// Show the toast. Be sure to specify the AppUserModelId
// on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
}
UPDATE
This seems to be working fine on windows 10
https://msdn.microsoft.com/library/windows/apps/windows.ui.notifications.toastnotificationmanager.aspx
you will need to add these nugets
Install-Package WindowsAPICodePack-Core
Install-Package WindowsAPICodePack-Shell
Add reference to:
C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd
And
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
And use the following code:
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
for (int i = 0; i < stringElements.Length; i++)
{
stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
}
// Specify the absolute path to an image
string imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png");
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier("Toast Sample").Show(toast);
The original code can be found here: https://www.michaelcrump.net/pop-toast-notification-in-wpf/
I managed to gain access to the working API for windows 8 and 10 by referencing
Windows.winmd:
C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral
This exposes Windows.UI.Notifications.
You can have a look at this post for creating a COM server that is needed in order to have notifications persisted in the AC with Win32 apps https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/10/16/quickstart-handling-toast-activations-from-win32-apps-in-windows-10/.
A working sample can be found at https://github.com/WindowsNotifications/desktop-toasts

How to automate upload multiple files using sikuli and selenium webdriver in java

I am new with sikuli, Unable to generate Sikuli script for upload functionality for web application.
Please note that typically, you can automate file upload scenario using Selenium only, no need for Sikuli.
For uploading a file you just need to callsendKeys() method (with file path as argument) on the WebElement that is displayed for file uploading. Code goes like this:
//Put this for textbox near to upload button
driver.findElement(By.id("id_or_other_locator_goes_here")).sendKeys("file_path_goes_here");
And then click the upload button:
driver.findElement(By.xpath("locator_for_upload_button")).click(); // Click Upload button
Sikuli :
I have used Sikuli to automate file download scenario in IE and below are the steps for this:
First capture image of Save button in File download dialog box and save it
Put Sikuli jar in your Java project
Use following code snippet
// Code:
//Save the file in Downloads directory by using on Sikuli
ScreenRegion s = new DesktopScreenRegion();
Target target = new ImageTarget(new File("SavedImagePath.png"));
ScreenRegion r = s.find(target);
Mouse mouse = new DesktopMouse();
if (r != null) {
mouse.click(r.getCenter());
Thread.sleep(5000);
} else {
System.out.println("Unable to click using Sikuli")
}
Thanks sandeep!
tried below script using Screen and Pattern class of Sikuli to capture desktop based file from open folder windows at run time and it works!!
String FileToUpload = "/location of file to upload/"
String fileNameLoc = "/fileName_input sikuli image location"
String openButtonLoc = "/Open button sikuli image location/"
//Code to perform action using action using sikuli script
Screen src = new Screen();
src.setAutoWaitTimeout(80);
Pattern fileName = new Pattern(fileNameLoc).similar((float) 0.5);
if (src.exists(fileName, 10) != null)
{
System.out.println("File Name Pattern exist..");
Match match = src.getLastMatch();
match.find(fileName);
match.click(fileName);
match.type(fileName, FileToUpload);
match.setAutoWaitTimeout(50);
}
else
{
System.out.println("File Name pattern not found on screen..");
}
Pattern open = new Pattern(openButtonLoc).similar((float) 0.5);
if (src.exists(open, 5) != null)
{
System.out.println("Open Button pattern exist..");
Match match = src.getLastMatch();
match.find(open);
match.click(open);
match.setAutoWaitTimeout(30);
}
else
{
System.out.println("Open buton pattern not found on screen..");
}

Online editor for word files and way to preview files using GWT

I have two requirements in my GWT 2.4.0 + GXT 2.2.4 + Amazon project,
We store the word documents in our app only (each login can access only his docs). Now i want that user can edit own word document online like ZOHO writer does. How can i achieve this functionality in my app?
We also stores the images, text files, word files, PDF files and others too. I want to show preview of those files when user clicks on the file. something like, docs.com. How to achieve this too?
I just need guidance that how can i achieve this two requirements. Any suggestion is appreciated.
Thanks.
GWT has come up with Wrapper class of Code mirror library for XML
Editor check this this is for client side
public XMLEditorPanel(int height, int width, final String xmlToDisplay) {
this.xmlToDisplay = xmlToDisplay;
setHeaderVisible(false);
setHeight(height);
setWidth(width);
config = new CodeMirrorConfiguration();
config.setLineNumbers(true);
config.setTextWrapping(false);
config.setAutoMatchParens(false);
editor = new CodeMirror(config);
editor.addInitializeHandler(new InitializeHandler() {
public void onInitialize(InitializeEvent event) {
editor.setParser(CodeMirror.PARSER_XML);
editor.setIndentUnit(2);
editor.setFocus();
if (xmlToDisplay != null && xmlToDisplay != "" && xmlToDisplay.length() > 0) {
editor.setValue(xmlToDisplay, false);
} else {
editor.setValue(" ", false);
}
editor.reindent();
}
});
editor.addValueChangeHandler(new ValueChangeHandler<String>() {
#Override
public void onValueChange(ValueChangeEvent<String> event) {
XMLEditorPanel.this.xmlToDisplay = editor.getValue();
}
});
add(editor);
}

Manipulation and Touch events not firing, but mouse events do?

I have a Samsung LD220Z multi touch monitor, and when I'm experimenting with some WPF and touch features the touch events arent firing. The mouse down event seems to be firing however.
Does this mean that I have to take into account that not all touch screen behave the same, and how do I get the touch inputs on my screen? I've tried the Windows 7 Touch pack that microsoft released. And the multi touch features seems to work there.
Any suggestion on how to proceed with this?
Event touchstart WORKS but touchend not. You can use onmouseup="SOMEfun()"
Even the Samsung Galaxy 3 is a problem with the trigger event.
Add the first event and thay will be working on but
Two scenario :
1)first add onmouseup and than tauchstart or better
2)check mobile or desktop and than add proper events
You can use my detectbrowser function , its very nice (give a name of browser type like mobile_chrome_android_tablet or firefox_desktop , safari_ipad)
Make NOMOBILE global , you can simply replace var NOMOBILE =0; with window["NOMOBILE"]=0;
download browser and device detector :
detect browser and device also class
Class name is DETECTBROWSER()
(on first line in script)
var BROWSER = new DETECTBROWSER()
Check this BROWSER.NAME
This is even crazy't script . Track 10 fingers at same time (in canvas2d)
link : https://github.com/zlatnaspirala/multi-touch-canvas-handler
example for 1)
document.getElementById('myCanvas').addEventListener('touchstart', function(event) {
event.preventDefault();
var touch = event.touches[0];
/* Avatar go left */
if (touch.pageX < 235) {
if (backgroundX < 0){
left = 1;
}
/* Avatar go right */
if (touch.pageX > 470) {
right=1;
}
/* Avatar go lower distance */
if (touch.pageX > 235 && touch.pageX < 470 && touch.pageY >250 ) {
distance--;
}
/* Avatar go to high distance */
if (touch.pageX > 235 && touch.pageX < 470 && touch.pageY <250 ) {
distance++;
}
} ,false);
// solution for touchend
function ENDoff(){
if (moveLEFT==1) { moveLEFT=0; }
if (moveRIGHT==1) { moveRIGHT=0; }
}
HTML CODE
<canvas id="myCanvas" width="480" height="960" onmouseup="touch_UP();"></canvas>

Resources