A developer tool : Stanley (beta)

Written by Xavier Gouchet - 22 march 2013 - no comments

Recently I needed to know what intents were used by an app on my phone, simply out of curiosity and to learn how to have similar features in one of my app.

There aren't so many way to do this, and so I designed and developped an App to take a look at an App, from a developper point of view. So here it is, in public beta.

Stanley Preview

Stanley can list all package installed on any device, and for any given package, lets one see the Activities, Services, Broadcast Receivers, Content Providers, and more.

More over, it can export the package's original manifest into a readable XML, to see what lies in the intent filters for instance.

It is not yet available on the Play Store, but you can already try it by downloading the APK attached to this post. Any feedback on this app will be welcomed.

Stanley 1.0 (Beta) APK (562 Kb)

Stanley on Google Play

Enabling / Disabling activities at runtime

Written by Xavier Gouchet - 20 february 2013 - no comments

Sometimes, you might want an activity to be available only under specific conditions. But you may want to completely disable it at runtime when some conditions are met. For instance based on the time, or the user geolocation.

This could also let one have different activities based on the user's configuration

You can do so simply by using the PackageManager. In the following example, I disable an activity and enable another one.


PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(new ComponentName(this, ActivityC.class), 
    PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
pm.setComponentEnabledSetting(new ComponentName(this, ActivityA.class), 
    PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);

The manifest declares the two activities with the same intent filter, namely the home screen shortcut. But using the previous code, I'm able to get a single one of them in the launcher menu at any given time.

Axel v2.3 : quick actions and clipboard support

Written by Xavier Gouchet - 15 february 2013 - no comments

Today, the latest version of Axel was launched, bringing many new features to make XML edition simpler.

New version

First of all, I added an implementation of the Done / Discard UI pattern. This make a much clearer interface when editing a node.

Then I added many ways to interact differently with nodes. A friend of mine once taught me that a user must be able to perform a single action in many different way, and better, should be able to change the way an action must be performed.

Quick Actions

So from now on, Axel lets you choose what happens when you tap, double tap or long press a node. By default, actions are edit on tap, add a child on double tap and bring the context menu on long press.

Axel : quick node actions

Speaking of quick action, I used the NewQuickAction library to add a better looking quick action. The same actions are available, with new ones.

Cut, Copy, Paste

A brand new feature is that Axel now support the integration with the Android clipboard, with the famous cut, copy and paste operations. Cut and copy will put the xml node (and hierarchy) as xml text in the clipboard, and psat will parse the clipboard content and insert it inside the selected node's hierarchy.

And as always, if you have any trouble with one of my app or one of my repo on github, please let me know.

Android app on Google Play Fork me on GitHub

A developer tool : AndroidXRef

Written by Xavier Gouchet - 06 february 2013 - no comments

The Android source code is full of information, and I never spend a week without having to find a piece of code in there. The problem with it is that I had to download the git repo, and to use my OS's search to find the relevant piece of code.

Not anymore, thanks to AndroidXRef, a search engine for the Android Open Source Project. Although it's still in beta, it is very usefull to find information on how things are implemented in Android.

A more complete Activity Lifecycle

Written by Xavier Gouchet - 05 february 2013 - no comments

In one of my application, I want to perform an action when the user has been idle for more than n minutes.

While searching the web I found those two callbacks in the Activity class : onUserInteraction() and onUserLeaveHint , both available since Cupcake.

The first one is simply called whenever an interaction is consumed by the activity : touch, key event, trackball event. The second is called just before onPause() when the user leaves your Activity on purpose. For example by pressing the home button, launching another activity from the notification bar. It won't be called when an Activity generated by the system comes in the foreground (an incoming phone call for instance).

And there are a lot more callbacks in an Activity that one can override. So, after some extensive logging and reading through AOSP sources, here's a new and more complete Activity lifecycle graph, with all the callbacks one may find usefull. I also included the callbacks sent to an Activity's fragments.

Android Full LifeCycle

Feel free to add any remark to make this diagram as accurate as possible.

A developer tool : Quick REx , Eclipse Regexp Plugin

Written by Xavier Gouchet - 01 february 2013 - no comments

Now and then, a little Regexp is necessary. Recently, I had to create a couple of regexp for my Android XML Editor. When the Regexp is complex, designing it from memory is almost impossible, and one needs a tool to write and test the Regexp.

Here is a little Eclipse plugin I found recently. In short, it's a Regex editor, with a couple of useful features:

  • preview of matches (and groups) in a user defined input;
  • a button to escape the sequence to be parsed in a Java String;
  • Ctrl-Space completion to insert common patterns, quantifiers, ...;
  • flags and options to match Pattern options.

Quick REx Eclipse plugin

Checkout the official Quick REx website, or install it in Eclipse using the following update-site URL : http://www.bastian-bergerhoff.com/eclipse/features.

Taming the LogCat

Written by Xavier Gouchet - 30 january 2013 - no comments

A couple of days ago, a question popped on StackOverflow, asking how to link a log line in LogCat to the source code, just like it happens when you Log an exception.

The first answers where to add a fake Exception. Naturally, there will be the line you want, but also a lot of noise in your LogCat.

Then someone proposed a method to simulated an exception Log, without the whole stacktrace (see the answer here).

The solution works fine, but can be quite verbose. With a little bit of try and error, I found out that the most important part is the "at (file.java:42)". It doesn't matter where it is in the message. You can even have mor than one, it only takes into account the last one.

So I worked out a LogLink class to use this systme anywhere and seamlessly. Here's an example of how it works :


	// can be one of INSERT_FIRST, INSERT_LAST or INSERT_NONE
	// default value is INSERT_LAST, and you can call it only once
	LogUtils.setInsertMode(LogUtils.INSERT_LAST); 
	
	// also exist as v, d, w, e and wtf 
	LogUtils.i("MyClass", "A message");

The previous code will output the following output

MyClass     A message at (MyClass.java:42)

You can see and download the LogUtils class here