Oct
24

Posty - Poll on new features

I created a small poll to understand which are the most “urgent” features for the next release of Posty, which will be ready around the end of the year.







If the list does not include what you’d like to see in the next version of Posty, please drop a line in the comments.

Share/Save/Bookmark

Oct
20

Using a Url Shortening service in Adobe Air

Url shortening services are getting popular, especially now that microblogging networks are extensively used. Since the length of a microblogging post is usually limited, a shortened url comes handy for it saves precious characters.

A shortened url is a sort of “compressed” url. For example if you point your browser to: http://is.gd/2 you will be redirected to google.com, this way saving seven characters. How comes? Because there are services which can build a shortened url given the original one. Every time you enter a shortened url they redirect your browser to the original. Maybe the case of google.com is not representative, because you save “only” seven characters. Think of posting a google maps address like this:



http://maps.google.com/maps?f=q&hl=en&geocode=&q=manhattan&ie=UTF8&z=17&iwloc=addr



Its shortened version is: http://is.gd/3k7B


Can you count how many characters do you save? Many!

Since I recently implemented a very similar feature in Posty, I will now show how to use a simple url shortener service in Adobe Air.

The interface will be made of:

  • a text input, where we can type the original url, to be shortened
  • a button, to trigger the shorten service
  • a text area to show the result

We put these three widgets in a VBox as in the following snippet of code.

1
2
3
4
5
<mx:VBox>
  <mx:TextInput id="originalURL" />
  <mx:Button id="shorten" label="Shorten" click="shortenLink()"/>
  <mx:Text id="result"/>
</mx:VBox>

The service which we’ll use is http://is.gd/ which is very reliable and simple to interact with. The api documentation is reported here. As you can see it is very easy to use the api. All it is needed is the url, provided as a parameter named longurl. For example, to shorten google.com, we have to call the following url:


http://is.gd/api.php?longurl=www.google.com


When we click the button we trigger the shortenLink() function (line 3), which is defined as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private var loader:URLLoader = new URLLoader();
 
private function shortenLink():void {
    var request:URLRequest = new URLRequest("http://is.gd/api.php?longurl="+originalURL.text);
    loader.addEventListener(Event.COMPLETE, shortenSuccess, false, 0, true);
    loader.addEventListener(IOErrorEvent.IO_ERROR, shortenError, false, 0, true);
    loader.load(request);
}
 
private function shortenSuccess(e:Event):void {
    loader.removeEventListener(Event.COMPLETE, shortenSuccess);
    loader.removeEventListener(IOErrorEvent.IO_ERROR, shortenError);
    result.text = originalURL.text + " shortened is " + e.currentTarget.data;
}
 
private function shortenError(e:IOErrorEvent):void {
    loader.removeEventListener(Event.COMPLETE, shortenSuccess);
    loader.removeEventListener(IOErrorEvent.IO_ERROR, shortenError);
    result.text = "Error in shortening " +originalURL.text;
}

As you can see in the code, we prepare a request to load the url (line 4) specified in the API documentation and we append the url inserted by the user.
The url shortener is a web service. You call it, but you do not get an immediate response. It takes a while, few seconds or milliseconds. This is why you need to set listeners, which are triggered when the service responds. We set up two listeners, one in case of success (line 5) and one triggered when there is some error in the process (line 6). In case of success, the listener function shows the shortened link (line 13). It notifies failure in case of error (line 19).

The only thing left is to couple logic and graphics by importing the actionscript file. Now our mxml file looks like this:

1
2
3
4
5
6
<mx:Script source="ShortenerController.as"/>
<mx:VBox>
  <mx:TextInput id="originalURL" />
  <mx:Button id="shorten" label="Shorten" click="shortenLink()"/>
  <mx:Text id="result"/>
</mx:VBox>

And we can run the code to get the response from the web service.


The source code for this post is available here.



ps:
In principle the same code works for Flex, but if you try to run it you’ll get a Sandbox violation message, because the Flash player is not allowed to load data from a different domain, unless the server specifies a cross-domain policy file.

Share/Save/Bookmark

Oct
18

Posty 1.6 is out

A new version of Posty has been released today. This is the best release of Posty ever with a lot of new features!

  • Automatic updates. Upon confirmation Posty downloads and installs new versions.
  • Improved usability of login forms (which show up when needed)
  • Clickable in-text links
  • Url shortening (via http://is.gd/)
  • Support to Twitter Direct Messages
  • Support to Identi.ca Direct Messages
  • Configurable notifications of new Twitter updates
  • Support to Retweet
  • Support to Twitter favorites
  • Support to Identi.ca favorites
  • Memorization of services to update, preselected on startup
  • Choice of active services to be displayed on startup



To download it go to Posty home page.


Special thanks to beta testers who helped identifying bugs and collaborated by sending details.

Share/Save/Bookmark

Oct
10

No drop shadow when systemChrome is none

Tags: adobeair, flex

As you know the Adobe Air framework enables the addition of a drop shadow to applications. I happened to get into this issue when I was trying to add a dropShadow to Posty.

The WindowedApplication Flex tag includes two intuitively named tags: dropShadowEnabled, which is boolean, and dropShadowColor which expects an hexadecimal color.
So it is simple to write something like the following code:

1
2
3
4
5
6
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
        layout="absolute" 
        dropShadowEnabled="true" 
        dropShadowColor="#000">
 
</mx:WindowedApplication>

If you run the application you’ll see the expected result: a native window with a drop shadow effect.
That’s what I did in Posty. But (… there is always a but …) at first it did not work. I spend few minutes googling around. No response. Then it came to my mind that there are strange dependencies between the properties of the WindowedApplication and the properties defined in the -app.xml file.
Few trials and errors and … gotcha! I set the systemChrome of Posty to none. But apparently there is a conflict/dependency between this property and the dropShadowEnabled tag.


Conclusion: no drop shadow effect visible when systemChrome set to none.
I don’t know whether it is a feature or a bug …

Share/Save/Bookmark

top