AIR App can't capture mouse event & can't show context menu - air

I'm building a AIR application and I need a custom context menu.
My Problem is: There is no context menu in my application!
I searched for long while. Most people want to disable context menu, but I want to enable it. I know how to generate a context menu, but I can't even see the build in context menu.
The reason might be: My swf application cann't capture mouse event.
Anyone know the reason? Thanks very much!

You can implement like this:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
private function initApp():void {
var ctxMenu:ContextMenu = new ContextMenu();
var clsitem:ContextMenuItem = new ContextMenuItem("Close");
var edititem:ContextMenuItem = new ContextMenuItem("Edit");
var otheritem:ContextMenuItem = new ContextMenuItem("Etc.");
clsitem.addEventListener(Event.SELECT,closeApp);
ctxMenu.customItems.push(clsitem,edititem,otheritem);
this.contextMenu = ctxMenu;
}
private function closeApp(event:Event):void {
this.close();
}
]]>
</mx:Script>
<mx:Panel width="200" height="300">
</mx:Panel>
</mx:WindowedApplication>

Related

Listening for a file being clicked to - Eclipse Plugin

I am trying to write an Eclipse plugin where one of the features requires listening for when the user switches to another file in the editor via clicking.
For example, consider the screenshot below.
I want to know how to listen for when the user switching over to FakeClass.java via double-clicking on it in the Project Explorer or clicking on the tab in the editor. Furthermore, I would like to get information about the element that was clicked. Note that I am asking specifically about changing a file through the two means I asked above.
I am a beginner with Plugin development. It would be helpful to explain with that in mind. Thanks.
You can use an IPartListener to listen for changes to parts including a part being activated:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.addPartListener(listener);
The partActivated method of the listener is probably what you want:
#Override
public void partActivated(final IWorkbenchPart part)
{
if (part instanceof IEditorPart) {
IEditorPart editor = (IEditorPart)part;
IEditorInput input = editor.getEditorInput();
IFile file = input.getAdapter(IFile.class);
if (file != null) {
// TODO handle file
}
}
}
I don't know of a way to tell why the part was activated.

WinJS - Preventing two quick button presses

We have a situation in an application in WinJS where our serialised data is read from a file on disk, and depending on the page, different sections of the file are accessed.
The problem we have is that when a user double taps a control, button, listview etc, the system will try to read the file twice and sporadically blows up.
Is there a recommended route in WinJS to prevent or handle double presses on controls? other than something like manually disabling and re-enabling all buttons when pressed?
We've looked at some options, including overriding addEventListener, but none are perfect, any suggestions in this area would be greatly appreciated.
Additional: Whilst in this example the problem is reading a file, we have other applications where performing quick double presses on lists will try to navigate to a page twice (and add it to the nav.history twice), so it seems like there are a number of places and symptoms where this kind of thing could occur.
The best way is to disable the buttons while processing and reenable them when done. This will provide appropriate feedback to the user if things take longer than expected.
You could disable them via databinding rather than setting them all manually.
HTML
<button id="button1" data-win-bind="disabled: disabled">Click</button>
<button id="button2" data-win-bind="disabled: disabled">Click</button>
<button id="button3" data-win-bind="disabled: disabled">Click</button>
<button id="button4" data-win-bind="disabled: disabled">Click</button>
JavaScript
var bindingSource;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application has been reactivated from suspension.
// Restore application state here.
}
args.setPromise(WinJS.UI.processAll());
var disabledContext = { disabled: false }
var btn = document.getElementById("button1");
btn.addEventListener("click", buttonClickHandler, false);
WinJS.Binding.processAll(btn, disabledContext);
btn = document.getElementById("button2");
btn.addEventListener("click", buttonClickHandler, false);
WinJS.Binding.processAll(btn, disabledContext);
btn = document.getElementById("button3");
btn.addEventListener("click", buttonClickHandler, false);
WinJS.Binding.processAll(btn, disabledContext);
btn = document.getElementById("button4");
btn.addEventListener("click", buttonClickHandler, false);
WinJS.Binding.processAll(btn, disabledContext);
bindingSource = WinJS.Binding.as(disabledContext);
}
};
function buttonClickHandler(eventInfo) {
bindingSource.disabled = true
WinJS.Promise.timeout(5000).then(function (c) {
bindingSource.disabled = false
});
}
--Rob

Windowless (not chromeless) Adobe AIR app

What would be the best way to go about building an Adobe AIR app that doesn't have any windows (i.e. exists only in the system tray / dock)? I noticed that the default base tag in Flash Builder is <s:WindowedApplication> which seems to imply there'll be a window.
Should I just use <s:WindowedApplication> and call window.hide()? I saw there's another base class, <s:Application>, but I got the sense that was more for files that run in the browser. It seems like using window.hide() would briefly flash a window when the application starts which could confuse users. However I'd also ideally like to retain the ability to have the app open a window later if needed, or also to change the application from tray-only to windowed through an update.
You need to edit the app-config file to enable transparent chrome and visible = false. Then you need to change the WindowedApplication tag to and app your custom skin. You need to add control buttons for close etc, since that functionality isn't present in a web-app (since you have changed the tag). Also you need to add drag functionality. If you like to make your application re-sizable you need to add that too, manually.
In your manifest (-app.xml) file set systemChrome to none and transparent to true. The visible property is irrelevant, and the default is false anyway so ignore it.
you'll have to tweak this, import whatever classes are missing, etc... you could also do it as an mxml component and just set visible and enabled to false on the root tag. Fill up the trayImages array with the icons you want in the dock.
p
ackage{
import spark.components.WindowedApplication;
public class HiddenApplication extends WindowedApplication{
public function HiddenApplication(){
super();
enabled=false;
visible=false;
var trayImages:Array;
if(NativeApplication.supportsDockIcon||NativeApplication.supportsSystemTrayIcon){
NativeApplication.nativeApplication.activate();
var sep:NativeMenuItem = new NativeMenuItem(null,true);
var exitMenu:NativeMenuItem = new NativeMenuItem('Exit',false);
exitMenu.addEventListener(Event.SELECT,shutdown);
var updateMenu:NativeMenuItem = new NativeMenuItem('Check for Updates',false);
updateMenu.addEventListener(Event.SELECT,upDcheck);
var prefsMenu:NativeMenuItem = new NativeMenuItem('Preferences',false);
prefsMenu.addEventListener(Event.SELECT,Controller.showSettings);
NativeApplication.nativeApplication.icon.addEventListener(ScreenMouseEvent.CLICK,showToolBar);
if(NativeApplication.supportsSystemTrayIcon){
trayIcon = SystemTrayIcon(NativeApplication.nativeApplication.icon);
setTrayIcons();
trayIcon.tooltip = "Some random tooltip text";
trayIcon.menu = new NativeMenu();
trayIcon.menu.addItem(prefsMenu);
trayIcon.menu.addItem(sep);
trayIcon.menu.addItem(updateMenu);
trayIcon.menu.addItem(exitMenu);
}
else{
dockIcon = DockIcon(NativeApplication.nativeApplication.icon);
setTrayIcons();
dockIcon.menu = new NativeMenu();
dockIcon.menu.addItem(prefsMenu);
dockIcon.menu.addItem(sep);
dockIcon.menu.addItem(updateMenu);
dockIcon.menu.addItem(exitMenu);
}
}
function setTrayIcons(n:Number=0):void{
if(showTrayIcon&&(trayIcon||dockIcon)){
Controller.debug('Updating tray icon');
if(NativeApplication.supportsSystemTrayIcon){
trayIcon.bitmaps = trayImages;
}
else if(NativeApplication.supportsDockIcon){
dockIcon.bitmaps = trayImages;
}
}
else if(trayIcon||dockIcon) trayIcon.bitmaps = new Array();
}
}
}

how to set an adobe Air application initial window to full screen

I have an air app created from one of Adobe's Examples using javascript / HTML. Is it possible to change the descriptor file so the application launches full screen or maximized?
Or you could call the maximize(); function in the application creation Complete function.
Maybe this helps (from here: http://www.kerkness.ca/how-to-launch-an-adobe-air-windowedapplication-in-full-screen-mode/)
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
<mx:Script>
<![CDATA[
private function init():void
{
systemManager.stage.displayState=flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE
}
]]>
</mx:Script>
</mx:WindowedApplication>
try this one.
onCreationComplete - call this method of the main application creation complete
private function onCreationComplete():void{
var current:Screen;
var scrArray:Array = Screen.screens;
var screens:Array = Screen.getScreensForRectangle(stage.nativeWindow.bounds);
(screens.length > 0) ? current = screens[0] : current = Screen.mainScreen;
this.width = current .bounds.width ;
this.height = current .bounds.height;
this.nativeWindow.x = 0;
this.nativeWindow.y = 0;
}

Launching a browser window from an AIR Application

I recently built an AIR app using HTML, CSS and JavaScript. In the web version there is a button on the Capacity tab that opens a new window with the calculated results. After packaging this into an AIR application the app attempts to open the new window but fails.
I read about doing such here, but I am not exactly sure how to implement the code (which follows below).
I would appreciate some guidance to know where this code would go. If there is an "easier" way to accomplish the same results, I am all ears.
Thanks!
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:HTML id="htmlComp" width="100%" height="100%" location="http://www.rediff.com"complete="addEventListenersToLinks(event)" />
<mx:Script>
<![CDATA[
private function addEventListenersToLinks(e:Event):void
{
var dom:Object = e.currentTarget.domWindow.document;
var links:Object = dom.getElementsByTagName("a");
for(var i:Number = 0; i < links.length; i++)
{
if(links[i].target.toLowerCase() == "_blank" || links[i].target.toLowerCase() == "_new")
links[i].onclick = linkClickHandler;
}
}
private function linkClickHandler(o:Object):void
{
navigateToURL(new URLRequest(o.currentTarget.href),"blank");
}
]]>
</mx:Script>
</mx:WindowedApplication>
This was a lot easier than I thought. Basic JavaScript:
CapacityWindow = window.open(document.location, 'CapacityWindow', 'toolbar=1,scrollbars=1,menubar=1,width=800,height=950');