"; */ ?>


10
Jan 11

Android: Using Intents and Intent Filters to Leverage Other Apps

Cyanogen LogoUsing “Intent Filters” is a very powerful way to connect different applications together which allows greater reuse and makes a user experience transparent to the fact that more than one application is used to achieve a certain task.

Here is an example that is discussed in “A Beginner’s Guide to Android” Google I/O 2010 talk.

Let’s say there is an application that finds hotels and would like to use another application to book it. For that it creates an implicit “Intent” where it says: “hey android, I intent to book this hotel, please find an application that is capable of booking it, and pass the data to do the booking”:

String action = "com.hotelapp.ACTION_BOOK";
String hotel = "hotel://name/" + selectedHotelName;
Uri data = Uri.parse( hotel );
 
Intent bookingIntent = new Intent( action, data );
 
startActivityForResult( bookingIntent );

Now let’s say there is such a booking app installed on a device. Then, in its manifest, it will announce itself through the “intent-filter”, as an application capable to perform this action, e.g. “com.hotelapp.ACTION_BOOK”, to get the data from another app and book a hotel:

<activity android:name="Booking" android:label="Book">
    <intent-filter>
        <action android:name="com.hotelapp.ACTION_BOOK"/>
        <activity android:scheme="hotel"
                      android:host="name"/>
    </intent-filter>
</activity>

Within the “Activity” of a booking app, you can then “getIntent()” to find the one that was used, get the action along with the data and do the booking:

@Override
public void onCreate( Bundle savedInstanceState ) {
 
    super.onCreate( savedInstance );
    setContentView( r.layout.main );
 
    Intent intent = getIntent();
 
    String action = intent.getAction();
    Uri data = intent.getData();
 
    String hotelName = data.getPath();
 
    // Providing booking functionality
    // ... ...
 
    setResult( RESULT_OK, null );
    finish();
}

THE TAKE AWAY: Think about exposing functionality ( can be full of partial workflows ) of your apps in order for other developers / apps to use. At the same time check what is already exposed for you to leverage from other developers / apps.

P.S. Read more about Intents and Intent Filters


07
Jan 11

Tomboy on Mac

Tomboy On MacOn “from Ubuntu to Mac” journey I don’t leave my friends behind. Tomboy is such a friend. Plus I already have several hundreds on notes in Tomboy format, so the choice for a note taking app is very obvious here.

To install Tomboy on Mac there are only two things that need to be done:

1. Download Tomboy ( Mac App ): http://projects.gnome.org/tomboy/download.html ( unzip, copy to /Applications )

2. Install “Mono” framework (a .NET framework for *nix systems): http://www.go-mono.com/mono-downloads/download.html

To migrate existing notes ( e.g. *.note ), I had to do a 30 seconds digging. It appears that unlike on Linux, where notes live under “~/.tomboy”, on Mac notes live under:

~/Library/Application Support/Tomboy/

So that is the place to copy all the existing notes to. Once copied, Tomboy is all good to go.

Welcome to my new OS X world Mr. Tomboy!


07
Jan 11

Starting with Scalate

scalateScalate: Scala Template Engine: like JSP without the crap but with added Scala coolness

Here is a one minute way to start playing with Scalate: 30 seconds to finish reading this + 15 seconds to calm inner excitement + 15 seconds to actually do it. Get ready.. it is that simple.

( Step 1 is OS X based, check these install instructions in case your OS is different ):

Step 1. Install Scalate ( makes sense to install Scala as well, if you don’t have it )

sudo brew install scala
sudo brew install scalate

Step 2. Create a Scalate project

scalate create guice org.dotkam scalatez

where “org.dotkam” is a user defined groupId and “scalatez” is a user defined artifactId [ hellllo maven ]

NOTE: "scalate create jersey org.dotkam scalatez" may give you "Invalid syntax: No such archetype 'jersey' possible values are (empty, guice)" depending on the current Scalate version. Don't be distressed: use 'guice' as shown above

Step 3. Run it

cd scalatez/
mvn jetty:run

Once you see

2011-01-07 14:28:42.597:INFO::Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server

Fire up the browser and go to “http://localhost:8080

Scalate Default Home Resource

DONE.

At this point you are good to start working with the Scalate project.
Let’s modify the current home page that you see in your browser:

vi src/main/webapp/WEB-INF/org/dotkam/scalatez/resources/HomeResource.index.scaml

once you save it, no need to restart: Jetty would pick you changes immediately ( e.g. “scanIntervalSeconds” parameter ), so just refresh that browser:

Scalate Custom Home Resource


04
Jan 11

Edit Keyboard Layout on Mac

Moving from several years of hardcore Ubuntu life to Mac is “a bit” challenging, but hey.. bring it on!

First thing that I needed to do is to be able to type.. Well yea, English is easy, since Mac does come with US keyboard that ironically comes with English letters. However what about people who are fortunate to know and love another language ( besides English )? Easy, you’d say: Mac has gazillions of different layouts ( a.k.a. “Input Sources” ) available:

mac keyboard input sources

Well, what if none of them suites me? Let’s take a look at the Russian Phonetic layout that comes with OS X:

russian phonetic layout mac

Maybe someone is ok with this layout, but many letters here are quite far from being “phonetic”. Leaving this be would result in many “typing in frustration” hours when you think you pressed “a”, but it was “b”, etc.. But don’t give up just yet, there is an awesome solution: Ukelete which is an excellent Unicode Keyboard Layout Editor for Mac OS X.

So switch to a “Russian Phonetic” layout:

Choosing Russian Phonetic Layout

Now start Ukelete, go to “File –> New From Current Input Source”:

New From Current Input Source

You should see the default layout in Ukelete window now:

Russian Phonetic Layout Ukelete

You are almost done.. Now just play a little “Swap Keys” game to get where you need to be:

Ukelete Swapping Keys

And get that final layout that you love:

Russian Phonetic Final Layout

Now save it as a “keyboard layout file”:

Save As Keyboard Layout File

to “/Library/Keyboard Layouts/”.

Now go to the “System Preferences –> Language & Text –> Input Sources”, and you should see a new “Russian – Phonetic” layout:

New Russian Phonetic Input Source

You are done :)

P.S. Another thing is to remap CapsLock to Option key via “System Preferences –> Keyboard –> Modifier Keys”:

Remap CapsLock

and change the shortcut to switch input sources ( keyboard layouts ) to “CapsLock + Tab”:

Remap CapsLock

Happy typing!


01
Dec 10

To Yammer through Corkscrew and Cygwin

The whole thing started when I wanted to use Yammer from behind a corporate firewall. The only laptop I had handy at that moment had Windows on it, so I thought, well.. I’ll

  • install Cygwin ( a Linux-like environment for Windows )
  • download and compile corkscrew ( enables SSH connections over HTTP/HTTPS proxies )
  • set up my proxy server in “$HOME/.ssh/config”:
  • Host *
      ProxyCommand corkscrew myproxy.com 8080 %h %p
  • forward X11 with ssh:
  • export DISPLAY=localhost:0.0
    ssh -2 -4 -C -X -v USER@SERVER
  • start firefox, and login to Yammer
  • DONE

But… Cygwin is not Ubuntu :)

First error I got after a fresh cygwin install was

mkdir: cannot create directory `/cygdrive/h': Permission denied

So here I had to make sure that my “H:” drive is unmapped, and I needed to add:

set HOMEDRIVE=
set HOMEPATH=
set HOMESHARE=

to “C:\cygwin\cygwin.bat” before “bash –login -i” line

The next error was slightly different, but also resembled the first one a lot:

mkdir: cannot create directory `/cygdrive/h': No such file or directory

Here I had to just cruelly delete “C:\cygwin\etc\passwd”

Now moving forward, I downloaded the Corkscrew, configured it ( ./configure ), and was about to compile it when I got:

$ make
gcc -DHAVE_CONFIG_H -I. -I. -I. -I.    -g -O2 -c corkscrew.c
In file included from /usr/include/cygwin/in.h:21,
                 from /usr/include/netinet/in.h:14,
                 from /usr/include/arpa/inet.h:14,
                 from corkscrew.c:2:
/usr/include/cygwin/types.h:120: parse error before "int16_t"
/usr/include/cygwin/types.h:124: parse error before "int32_t"
/usr/include/cygwin/types.h:128: parse error before "int64_t"
/usr/include/cygwin/types.h:137: parse error before "uint16_t"
/usr/include/cygwin/types.h:141: parse error before "uint32_t"
/usr/include/cygwin/types.h:145: parse error before "uint64_t"
/usr/include/cygwin/types.h:154: parse error before "u_int16_t"
/usr/include/cygwin/types.h:158: parse error before "u_int32_t"
/usr/include/cygwin/types.h:162: parse error before "u_int64_t"
/usr/include/cygwin/types.h:177: parse error before "register_t"
In file included from /usr/include/netinet/in.h:14,
                 from /usr/include/arpa/inet.h:14,
                 from corkscrew.c:2:
/usr/include/cygwin/in.h:40: parse error before "in_port_t"
/usr/include/cygwin/in.h:81: parse error before "in_addr_t"
In file included from corkscrew.c:2:
/usr/include/arpa/inet.h:22: parse error before "inet_addr"
/usr/include/arpa/inet.h:24: parse error before "inet_lnaof"
/usr/include/arpa/inet.h:26: parse error before "inet_netof"
/usr/include/arpa/inet.h:27: parse error before "inet_network"
make: *** [corkscrew.o] Error 1

The fix is obvious, right? :) Just needed to add “#include <sys/types.h>” to “C:\cygwin\usr\include\cygwin\types.h”:

#ifndef _CYGWIN_TYPES_H
#define _CYGWIN_TYPES_H
 
#include <sys/types.h>			/* <<<<< add this line */
#include <sys/sysmacros.h>

Now when forwarding X11 traffic over SSH, depending on firewall settings, the port 6000 ( XDMCP ) is most likely blocked:

connect localhost port 6000: Connection refused

Once the port is open, a beautiful window with Firefox and unlimited opportunities shows up making you ready to concur the world!