Posts Tagged ‘icon’

Google Reader AIR app

Monday, October 29th, 2007

Download GReader-0_1.air

I was playing around with the actionscript to javascript bridge and built this Google Reader AIR app:

I find the unread count from ‘reading-list-unread-count’:

1
2
3
var html:HTML = ...
var window:JavaScriptObject = html.htmlControl.window;
var unread:String = window.document.getElementById("reading-list-unread-count").innerHTML.toString();

Then I generate a dock icon (ignore all the hard coded pixel math):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[Embed(source="/assets/app_icons/greader/icon_128.png")]
private var iconClass:Class;

[Embed(source="/assets/fonts/Verdana.ttf", fontName="GReaderDockIconFont", mimeType="application/x-font-truetype")]
private var fontClass:Class;
....

private function draw():void {  
  var icon:BitmapAsset = BitmapAsset(new iconClass()); 
      
  var shape:Shape = new Shape();
  shape.graphics.beginBitmapFill(icon.bitmapData, new Matrix(), true, false);
  shape.graphics.drawRect(0, 0, dimensions, dimensions);
  shape.graphics.endFill();
  
  shape.graphics.beginFill(0xDF0013);
  shape.graphics.drawCircle(32, dimensions - 32, 32);
  shape.graphics.endFill();
  addChild(shape);
  
  if (unreadCount > 0) addChild(buildText());      
}

public function buildText():Bitmap {
  var countText:TextField = new TextField();
  countText.embedFonts = true;

  var format:TextFormat = new TextFormat();
  format.font = new fontClass().fontName;
  format.color = 0xFFFFFF;      
  format.size = 26;
  format.align = TextFormatAlign.CENTER;
  
  countText.defaultTextFormat = format;
  countText.selectable = false;      
  countText.text = unreadCount.toString();
  countText.height = 32;
  countText.width = 54;
  
  var bitmapData:BitmapData = new BitmapData(64, 32, true, 0x00000000);
  bitmapData.draw(countText);      
  var bitmap:Bitmap = new Bitmap(bitmapData);
  bitmap.smoothing = true;
  bitmap.y = 128 - 52;
  bitmap.x = 4;
  return bitmap;
}

Set the dock icon with the generated bitmap data:

1
2
if (Shell.shell.icon is InteractiveIcon) 
  InteractiveIcon(Shell.shell.icon).bitmaps = icons;

For more info on dynamic dock icons, see Generating Dynamic Dock and System Tray Icons in AIR

I think the next step is taking a bunch of greasemonkey js scripts and adding them in. This might be how you would do that:

1
2
3
4
5
6
7
8
var html:HTML = ...
var window:JavaScriptObject = html.htmlControl.window;      
var head:JavaScriptObject = window.document.getElementsByTagName("head")[0];         
var script:JavaScriptObject = window.document.createElement('script');
script.type = 'text/javascript';
//script.src = 'http://lolcats.com/script.js';
script.innerHTML = "alert('HAI.. KTHXBYE');";
head.appendChild(script);

Update: I’ve seen it tack the CPU when interacting in a couple places so I will try to figure out if its AIR webkit being buggy or me. Also will fix the external link lameness at some point.

Update: Oops. Looks like it doesn’t work in Leopard.