AIR, Javascript, Prattsville N.Y., Windows

Adobe AIR Application – Prattsville NY Creek Gauge (Alpha release – Windows only)

Simple System Tray Icon application that keeps a small meter that displays the water level of the Schoharie Creek in Prattsville N.Y. within sight on the Windows desktop

This is a useless application to anyone other than people who live in Prattsville N.Y. and the surrounding area. It utilizes the data received from the unmanned experimental sensor located in Prattsville (the gage house is on the side of the creek down by the bridge). There is no Mac functionality at this time for this application (maybe later on). The code is less than elegant at this point. However, there is a view source context menu item if you would like to view the code anyway (Mac users unzip the installer).
I wrote this application for myself to keep an eye on the creek water level in my neighborhood – sorry if its not perfect at this point.

  • Downloads water level datum and default hydrograph every 30 minutes (And caches them on the system in case of disconnection).
  • Click on the icon to download and display the most recent NOAA hydrograph in the lower right corner of the viewport
    (click on it again to make it go away)

  • Icon displayed changes to reflect changes in the water level.
  • Added context menu items that open various pages related to Prattsville N.Y. in the default browser

Download Prattsville NY Creek Gauge
(Requires Adobe AIR)

				  File: PrattsvilleCreek.air
				CRC-32: 4d057fdb
				   MD4: 0f5aa9605d292368cb546fc55ef8d81c
				   MD5: f53dbe407bfc5b477c84a7d9f66d0071
				 SHA-1: fdf93f2f2af533d8e80c84ad1a7621a7269279c5
                

Advertisements
Standard
AIR, Javascript

Adobe AIR Helper File – IntrospectorAliases.js

Adobe AIR Introspector

Adobe AIR Introspector

IntrospectorAliases.js

When developing user interfaces in Adobe AIR and HTML/JavaScript you don’t have the luxury of using the browser tools you may be accustomed to using. What Adobe provides instead is the Introspector tool; which is similar to but not as feature rich as most browser tools. Hey, you have to look at the bright side, at least Adobe gives you the basics to work with.

This file was born as a bunch of functions I used to place at the bottom of the AIRIntrospector.js file. However, its not proper to change the files provided by a third party so I broke them off into this file. It usually saves me a bunch of typing while debugging my Adobe AIR user interfaces using the Introspector. Maybe it can save you a bit of typing too.

IntrospectorAliases.js


/**
 * log
 * Alias for air.Introspector.Console.log
 * @param {String} str
 */
function log(str){
    air.Introspector.Console.log(str);
}
/**
 * warn
 * Alias for air.Introspector.Console.warn
 * @param {String} str
 */
function warn(str){
    air.Introspector.Console.warn(str);
}
/**
 * info
 * Alias for air.Introspector.Console.info
 * @param {String} str
 */
function info(str){
    air.Introspector.Console.info(str);
}
/**
 * error
 * Alias for air.Introspector.Console.error
 * @param {String} str
 */
function error(str){
    air.Introspector.Console.error(str);
}
/**
 * dump
 * Alias for air.Introspector.Console.dump
 * @param {Object} obj
 */
function dump(obj){
    air.Introspector.Console.dump(obj);
}

// Almost forgot this part below

/*************************************************
 *************************************************
 * IntrospectorAliases.js Supplimentary
 * Include this at the top of page script
 * in order to leave console call functions
 * in source while not using the Introspector
 * 
 * Simply comment out the AIRIntrospector.js
 * include to turn off the Introspector while
 * testing. Doing this will avoid errors.
 *\
function log(str){air.trace(str);}
function warn(str){air.trace(str);}
function info(str){air.trace(str);}
function error(str){air.trace(str);}
function dump(obj){air.trace(obj);}
/**************************************************
***************************************************/

Standard
AIR, Google-Music-Search, Google-Open-Storage-Search, Javascript, Windows

Adobe AIR Application – Google Music Search

Adds Music Search functionality to Windows and Mac. Provides the functionality of the Google Music Search and Google Open Storage Search Chrome add-ons to Windows and Mac users. Opens up the Google search query in the default system browser whatever that may be.

application.xml

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<application xmlns="http://ns.adobe.com/air/application/1.5">
 <id>com.timothytocci.example.Google.Music.Search</id>
 <filename>Google.Music.Search</filename>
 <name>Google.Music.Search</name>
 <version>1.0</version>
 <description/>
 <copyright/>
 <initialWindow>
 <content>Google.Music.Search.html</content>
 <systemChrome>none</systemChrome>
 <transparent>true</transparent>
 <resizable>false</resizable>
 </initialWindow>
 <icon>
 <image16x16>icons/musicsearch_16.png</image16x16>
 <image32x32>icons/musicsearch_32.png</image32x32>
 <image48x48>icons/musicsearch_48.png</image48x48>
 <image128x128>icons/musicsearch_128.png</image128x128>
 </icon>
</application>

Google.Music.Search.html

<html>
 <head>
 <script type="text/javascript" src="lib/air/AIRAliases.js">
 </script>
 <script type="text/javascript">
 var thisVersion, currentVersion;
 var iconLoadComplete = function(event){
 air.NativeApplication.nativeApplication.icon.bitmaps = [event.target.content.bitmapData];
 }
 air.NativeApplication.nativeApplication.autoExit = false;
 var iconLoad = new air.Loader();
 var iconMenu = new air.NativeMenu();
 var showSearchCommand = iconMenu.addItem(new air.NativeMenuItem("Music Search"));
 showSearchCommand.addEventListener(air.Event.SELECT, function(event){
 showSearch();
 });
 var exitCommand = iconMenu.addItem(new air.NativeMenuItem("Exit"));
 exitCommand.addEventListener(air.Event.SELECT, function(event){
 air.NativeApplication.nativeApplication.icon.bitmaps = [];
 air.NativeApplication.nativeApplication.exit();
 });
 if (air.NativeApplication.supportsSystemTrayIcon) {
 air.NativeApplication.nativeApplication.autoExit = false;
 iconLoad.contentLoaderInfo.addEventListener(air.Event.COMPLETE, iconLoadComplete);
 iconLoad.load(new air.URLRequest("icons/musicsearch_16.png"));
 air.NativeApplication.nativeApplication.icon.tooltip = gettooltip();
 air.NativeApplication.nativeApplication.icon.menu = iconMenu;
 }
 if (air.NativeApplication.supportsDockIcon) {
 iconLoad.contentLoaderInfo.addEventListener(air.Event.COMPLETE, iconLoadComplete);
 iconLoad.load(new air.URLRequest("icons/musicsearch_128.png"));
 air.NativeApplication.nativeApplication.icon.menu = iconMenu;
 }
 checkVersion();
 showSearch();

 function checkVersion(){
 var appData = air.NativeApplication.nativeApplication.applicationDescriptor;
 var dp = new DOMParser();
 var xml = dp.parseFromString(appData, "text/xml");
 var version = xml.getElementsByTagName("version")[0].firstChild;
 thisVersion = version.nodeValue;
 var url = new air.URLRequest("http://weyou.us/apps/GoogleMusicSearch/version/");
 var loader = new air.URLLoader();
 loader.dataFormat = air.URLLoaderDataFormat.TEXT;
 loader.addEventListener(air.Event.COMPLETE, compareVersion);
 loader.load(url);
 }

 function compareVersion(e){
 currentVersion = e.currentTarget.data;
 if (currentVersion > thisVersion) {
 openInBrowser("http://weyou.us/apps/GoogleMusicSearch/");
 }
 }

 function gettooltip(){
 var temp = "";
 temp = "Google Music Search" + "\n";
 temp = temp + " Use google to find music.";
 return temp;
 }

 function showSearch(){
 var init = new air.NativeWindowInitOptions();
 var win = null;
 var height = 228;
 var width = 500;
 // adobe bug - should be centered perfectly
 var top = (air.Capabilities.screenResolutionX / 2) - (height / 2);
 var left = (air.Capabilities.screenResolutionY / 2) - (width / 2);
 var spot = new air.Rectangle(top, left, width, height);
 init.minimizable = true;
 init.maximizable = true;
 init.resizable = false;
 init.type = "lightweight";
 init.systemChrome = air.NativeWindowSystemChrome.NONE;
 win = air.HTMLLoader.createRootWindow(true, init, false, spot);
 var form = air.File.applicationDirectory.resolvePath("search.html");
 win.load(new air.URLRequest(form.url));
 }

 function openInBrowser(url){
 air.navigateToURL(new air.URLRequest(url));
 }
 </script>
 </head>
 <body>
 <!-- This page is never shown. -->
 </body>
</html>

search.html

<html>
 <head>
 <style>
 body {
 background-color: white;
 }

 input {
 height: 30px;
 width: 450px;
 }

 #goo {
 padding-top: 20px;
 }
 </style>
 <script type="text/javascript" src="lib/air/AIRAliases.js">
 </script>
 <script type="text/javascript">
 var win = window.nativeWindow;
 var stay = false;
 var staycount = 0;
 function close(){
 win.close();
 }

 function timeout(){
 if (!stay) {
 close();
 }
 else {
 staycount++;
 }
 if (staycount === 3) {
 staycount = 0;
 stay = false;
 }
 }

 function doquery(query){
 url = "https://www.google.com/search?q=" + encodeURIComponent(query);
 openInBrowser(url);
 }

 function openInBrowser(url){
 air.navigateToURL(new air.URLRequest(url));
 }

 window.onload = function(){
 var dlg = document.getElementsByTagName("body");
 dlg[0].addEventListener("mousedown", function(){
 stay = true;
 staycount = 0;
 win.startMove();
 }, false);
 dlg[0].addEventListener("mouseover", function(){
 stay = true;
 staycount = 0;
 }, false);
 var inpt = document.getElementById("query");
 inpt.addEventListener("change", function(){
 stay = true;
 staycount = 0;
 }, false);
 var btnmusic = document.getElementById("music");
 btnmusic.addEventListener("click", function(){
 var input = document.getElementById("query");
 var text = input.value;
 var query = 'intitle:index.of +?last modified? +?parent directory? +(mp3|wma|ogg|wav) +"' + text + '" -htm -html -php -asp -jsp -"Passwords"';
 doquery(query);
 win.close();
 }, false);
 var btnstorage = document.getElementById("storage");
 btnstorage.addEventListener("click", function(){
 var input = document.getElementById("query");
 var temp = input.value.split(" ", 2);
 var filetype = temp[0];
 text = temp[1];
 var query = 'intitle:index.of +?last modified? +?parent directory? +(' + filetype + ') +"' + text + '" -htm -html -php -asp -jsp -"Passwords"';
 doquery(query);
 win.close();
 }, false);
 setInterval(timeout, 5000);
 }
 </script>
 </head>
 <body>
 <center>
 <div id="goo">
 <img src="google_logo_front.png"/>
 </div>
 <br/>
 <div>
 <input name="query" id="query" type="text" align="center" placeholder="enter a bandname or filetype and query"/>
 <br/>
 <button id="music">
 <img src="google_music_search_button.png"/>
 </button>
 <button id="storage">
 <img src="google_open_storage_search_button.png"/>
 </button>
 </div>
 </center>
 </body>
</html>

Original Source

MD5: ff8765b516c027539d18693a8b0adc73

Install Music Search

MD5: d3084dfb2406a68a3957d63acffa33c1

 Adobe AIR application installers can be unzipped to inspect the code (if you don’t have 7-Zip you’ll have to change the file extension to .zip – do it on a copy).

Standard