Thursday, 29 March 2012

Removing default apps from a rooted android phone

I recently needed to remove some of those rubbish default apps you get on android phones. You know the ones, the ones that come with the phone but you can't uninstall.  It is especially annoying if you don't ever want to use them and they are taking up loads of space on your phone because you have an Android version prior to Froyo (2.2) so apps can't be installed to the SD card

One of my phones (a Sony Ericsson Xperia X8) is on Android 2.1 and I want it stay on that OS, but it was running out of memory.  I already rooted it some time back, and a quick google search came up with this great guide: http://androidadvices.com/remove-default-applications-rooted-android-phones/

I have one thing to add though, which is why I am writing this.  Once I'd uninstalled FourSquare, Facebook, Stopwatch, Planet3 and loads of other stuff I didn't want, I was surprised that they still showed as installed.  So I checked again with the article above, nope, definitely gone.  But they still show in my apps and the memory is still full.  Here is the solution:  Go into the app manager and 'uninstall updates'.  It will fail to uninstall (because the app is already gone) but now they don't display and the memory is freed.  Hurrah!

Monday, 19 March 2012

Using RoboGuice with BlackBerry Android Runtime

I have recently been porting Android application to run on the new BlackBerry Tablet OS 2.0 which includes an Android 2.3 runtime.  However, one of my apps kept failing the BlackBerry packager checks because:

3 uses-package com.google.android.maps
However my app wasn't using it, and a search of my code didn't reveal any uses of it either.
It turns out that, because I was using RoboGuice, which has a MapActivity, the BlackBerry packager was picking that up, even though I wasn't using it.

The only solution I could think of was to unpack the roboguice jar, delete the MapActivity class, then repackage it.  Then the BlackBerry packager was happy!

Hope this helps someone

Runtime Bean Wiring

Sproing provides an easy method of wiring an object into Spring at runtime when that object hasn't been created by Spring but needs access to Spring beans.

The SpringWirer class provides a static method that, given an object, will wire it into the existing application context and set the spring beans needed

public class Jedi {
  private Force force;
  public Jedi() {
    // wire this object up
    SpringWirer.wireBean(this);
    force.push();
  }
  // set the Force spring bean
  public void setForce(Force force) {
    this.force = force;
  }

In this example, the Force object can be accessed because it is a bean defined in Spring. At runtime, the SpringWirer.wireBean(this) call will wire the object into Spring, setting the Force object using the setter method

Sproing version 0.3.2 is available now from Sith Open Source

Sproing: Arbitrary Spring loading

Sometimes is is desirable to load spring when an arbitrary (ie, not containing a main() method) object is created. Sproing provides this for when another application is creating java objects in order to provide a route into your code (for example FitNesse, The Grinder etc) that you need to wire into spring. Sproing does this by loading any application context files you specify and then wiring the object into it, allowing you to inject beans at runtime.

Spring beans are weired using the AutowireCapableBeanFactory.AUTOWIRE_BY_NAME strategy, so your object needs to have setter methods with the same names as the beans you want to wire up. You need to create a subclass of ApplicationWirer and implement the getPaths() method to return the paths of the spring application context files you want to wire up

For example:
  public class YourAppWirer extends ApplicationWirer {
    public String[] getPaths() {
      return new String[] {
        "classpath:someApplicationContext.xml",
        "classpath:applicationContext.xml"};
    }
  } 


To wire up your object, all you need do is create a new instance of your overridden ApplicationWirer class in a constructor on your object, and call the wire() method

For example, using YourAppWirer in the above example:

  public class JediMindTrick {
    public JediMindTrick() {
      new YourAppWirer().wire(this);
    }
  } 

Provided you have defined public setter methods for any spring dependencies your object needs, and called them the same names as described above, spring will inject these at runtime. You can then write your object methods as normal

Sproing version 0.3.1alpha is available now from Sith Open Source

Creating a Spring Application

Creating a standalone (ie non-web) application can seem a little confusing to some. Sproing makes this easy by extending a Sproing class and implementing a method, and that's it!

All you need do is have your main (the class with the main() method that starts the application) extend ApplicationWirer and implement the getPaths() method that returns the path(s) to your application context xml files. Then a single call to the wire() method does the rest
import uk.org.sith.sproing.spring.ApplicationWirer;
public class Main extends ApplicationWirer {
  public static void main(String[] args) {
    Main main = new Main();
    main.wire(main);
  }
  public String[] getPaths() {
    return new String[] {"applicationContext.xml"};
  }

This code will start your application and load the applicationContext.xml file into spring with all the spring beans defined. Easy!

Sproing version 0.3.1alpha is available now from Sith Open Source

Sproing: Spring static ApplicationContext access

It is often useful to gain access to the ApplicationContext object in order to locate existing beans. Sproing provides a ApplicationContextProvider class that can be used anywhere in a spring application to access the application context like so:

 ApplicationContext ctx = ApplicationContextProvider.getApplicationContext(); 

If you have used Sproing to start the application and/or load Spring, you will automatically have access to this class. If you want to use this feature of Sproing in a web application, all you need to do is declare the ApplicationContextProvider as a spring bean in your spring xml file ie

 <bean id="applicationContextProvider" class="uk.org.sith.sproing.spring.ApplicationContextProvider"/>

Sproing version 0.3.1alpha is available now from Sith Open Source

Sproing: FitNesse-Spring integration

Sproing wires up FitNesse fixtures into Spring by loading any application context files you specify and then wiring the fixture into it, allowing you to inject beans into the fixture at runtime.

The fixture needs to implement SpringWirableFixture and extend your chosen FitNesse fixture. It is wired
using the AutowireCapableBeanFactory.AUTOWIRE_BY_NAME strategy - it needs to do this to work properly with
FitNesse, so your fixtures need to have setter methods with the same names as the beans you want to wire up

You need to create a subclass of AbstractFixtureWirer and implement the getPaths() method to return the paths of the spring application context files you want to wire up

For example:
   public class YourAppFixtureWirer extends AbstractFixtureWirer {

      public String[] getPaths() {

         return new String[] {
                  "classpath:fitnesseApplicationContext.xml",
                  "classpath:applicationContext.xml"};
      }

   }


To wire up your fixture, all you need do is create a default constructor (or setUp() method if using a fixture that
has one) and create a new instance of your overridden {@link AbstractFixtureWirer} class

For example, using YourAppFixtureWirer in the above example:


   public class TestFixture extends ColumnFixture implements SpringWirableFixture {

      public TestFixture() {
         new YourAppFixtureWirer().wire(this);
      }
   
   }


FitNesse will call the default constructor, wiring up your fixture with the bean factory. Provided you have defined
public setter methods for any spring dependencies your fixture needs, and called them the same names as described
above, spring will inject these at runtime. You can then write your fixture methods as normal

It can be downloaded from sourceforge