++dave;: Cucumber for Android!
Very useful post that's helping us probe the mysteries of android + cucumber.
++dave;: Cucumber for Android!.
How to Install Ice Cream Sandwich ROM on Motorola Droid X
I fully intend to do this in the near future, so I wanted to post it here to remind me.
How to Install Ice Cream Sandwich ROM on Motorola Droid X.
How to control orientation changes for fragments in a FragmentActivity with multiple fragments
I wasted several hours trying to fix this problem so once again i'm paying it forward in the hope it's helpful to someone else.
The problem is that it's difficult to control configuration changes in a fragment activity with multiple fragments when you need fragments to behave differently.
Here is my scenario:
I have a fragment activity that displays different fragments one at a time. The first fragment displayed is not allowed to change orientation, it must be locked in portrait.
However the next fragment I show in the same activity needs to be able to change on both portrait and landscape orientations.
Sure I could have just rewritten my code to have the other fragment start in a different activity but that's besides the point.
Anyway, what you have to do is make sure you can get configuration changes
Manifest code:
Activity code:
//
//
@Override
public void onConfigurationChanged(Configuration newConfig) {
if(fragment!=null && fragment.isResumed()){
//do nothing here if we're showing the fragment
}else{
setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT); // otherwise lock in portrait
}
super.onConfigurationChanged(newConfig);
}
The code above doesn't work by itself. You would think so but there's a problem where you never receive more onConfigurationChanged callbacks after you call setRequestedOrientation.
Luckily we can take advantage of the lifecycle of our fragment to help our activity get out of it's funk.
When our fragment resumes we can do the following:
Fragment code:
//
//
@Override
public void onResume() {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
..}
I also make sure that my activity goes back to portrait mode if I exit this fragment.
//
//
@Override
public void onPause() {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // set the activity back to //whatever it needs to be when going back.
super.onPause();
}
This ensures that the activity can go back to being stubborn about orientation changes while letting an individual fragment take over configuration changes while it's active.
I hope this is helpful! cheers!
Hot Text is released!
Hi,
I'm pleased to announce the release of Hot Text on the Android Market!
This is my first personal app. It was especially fun because I worked on it with my beautiful wife and the help of her awesome sister!
I'm real proud of this one and I hope you all enjoy it :)
cheers!
How To Properly Set SVN svn:externals Property In SVN Command Line
How To Properly Set SVN svn:externals Property In SVN Command Line.
Wanted to shout out to this post now that it's the third or fourth time I end up using it as reference while messing around w/ svn externals.
Thanks Artem Russakovskii!
Configuring Charles Web Debugger to work with Android devices and emulator
Quite a mouthful eh?
During my web days I became very attached to Charles as part of my development toolset. It was a sad day when I discovered it was difficult to get it to work with either the emulator, much less a phone.
My first attempt circa Android Froyo (2.2) yielded no success. It's still doable but you have to root your phone and download an app from the market. It was a bit frustrating given that the Charles documentation didn't provide a lot of insight.
A second attempt led me to try again on two Motorola phones running 2.3. It turns out that it is now possible to set a proxy when connecting to a wifi access point!!!
Oh happy day!
This means that we can have our phone point to the IP address of the computer running Charles. And just like magic Charles works!
First let's look at how to configure a phone, since it's easiest. Then we'll look at getting the emulator to work.
Configuring your android device to work with Charles.
Step 1:
Connect to your Wifi.
(note that your device and your machine running Charles need to be on the same network)
Set the port to the IP of your machine running Charles. Set the port to 8888.
To access the menu above on existing wifi networks simply long click the name. New networks will present the option when connecting.
That's it! Charles should work.
Now onto the second part.
Configuring the Android emulator to work with Charles.
When starting an emulator you can do one of two things:
Using the command line you can do something like:
emulator -http-proxy localhost.:8888 -port 5554 -debug-proxy @Nexus
Optionally you can set the same emulator in the run configurations in Eclipse.
Watch out!!! this technique only works with revision 13 and above of the Android SDK. r12 was broken and had a bug logged against it but has since been fixed in 13. Make sure you're up to date!
Remember that you have to make sure the emulator starts using these additional arguments. If you already have one running these extra arguments will have no effect as the proxy will not be created.
Charles gotchas:
If your apps use https you may run into some problems with the server rejecting your certificates (or lack thereof).
I think there is a way to get Charles to provide a certificate on behalf of your device but I haven't figured that part out yet.
In the mean time I've had luck using the FakeX509TrustManager when creating an https connection from within my app.
private static SSLContext createEasySSLContext() throws IOException {
try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new TrustManager[] { new FakeX509TrustManager() }, null);
return context;
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}
I hope this is helpful!
More on testing automation in Android
Test automation has been a particularly interesting topic for me in the past few weeks. I wanted to share some of the info I've gathered hoping that it will be useful to someone else. In my previous post I talked about Testdroid which makes use of robotium and also can make MonkeyRunner tests The plugin provided by Testdroid is essentially a way to record and script UI events.
It will generate test cases for you where you can then go in and add assertions. It's pretty neat.
Now i'd like to talk a little bit about Robolectric. Robolectric is created and maintained by folks at Pivotal labs. Robolectric runs within your VM which makes it very cool.
This means you don't need the emulator to run tests. That's pretty cool! I definitely recommend giving this a try. I'm going to deep dive into Robolectric to use on my current personal project.
I'll post some of those results later.
How to ensure views are set below the fold on a device.
Did you ever have a view that you needed to make sure started off below the screen so the user could scroll to it later?
Sounds weird but I had to do that for a designer's crazy ass UI.
Wasn't as simple as I first thought so I wanted to share the code.
Turns out that onLayout() doesn't always work. you sometimes don't get all of the dimensions for the views you're interested in and it's just a mess. I guess all the measures() for each view haven't happened yet. Who knows, or rather who cares. It didn't work so I had to find a way that did.
Turns out you can listen for layout change events by adding a listener to the ViewTreeObserver of a view, which notifies of many layout changes on your view. If you add a OnGlobalLayoutListener to the ViewTreeObserver of the view you're interested in you are guaranteed to have gotten the measure() values at that point.
You can then use any way you want to set the position of your view. In my case I chose to use padding. Anyone have a better suggestion?
ViewTreeObserver vto = bottomContainer.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Display display = getWindowManager().getDefaultDisplay();
LinearLayout bottomContainer = (LinearLayout) findViewById(R.id.footer_container);
ViewGroup profileBar = (ViewGroup) findViewById(R.id.profileBar);
RelativeLayout sv = (RelativeLayout) findViewById(R.id.main);
bottomContainer.setPadding(0, display.getHeight(), 0, 0);
bottomContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
bottomContainer.forceLayout();
}
});
Testdroid – a great test solution for Testing Automation in Android
Because of fragmentation in Android it is very important to test you apps in as many devices as you can get your hands on. You've heard it all before right?
So have I. Testing mobile apps still remains quite a daunting task. For larger projects such as the one I'm currently working on Test Automation becomes a necessity very quickly. It is simply too time consuming, error prone and difficult to test manually. So what can you do? What tools are available to help you automate UI testing?
Luckily, Android comes to the rescue. Android's testing framework is top notch and easy to work with. They make life worth living.
Android's testing toolset is based on JUnit and is very well integrated for android projects into Eclipse. Android instrumentation provides a way to hook into android components and load applications.
The testing framework also provides a way to create Mock objects to help you isolate parts of your application for specific tests.
You also get the monkeyrunner tool, a python framework for executing android apps.
All in all you get a very powerful set of tools that can enable you to produce detailed and efficient testing solutions.
But wait! there's more! Since of course this framework is so great, there are developers building great testing solutions based on these tools. One that i'm starting to dig into is robotium. Robotium is a test framework aimed at test case developers to write function, system and acceptance tests scenarios for apps.
Adding yet more value to this are companies like bitbar who provide a plugin for Eclipse called testdroid which makes recording a UI test of your app, child's play. Very cool and worth checking out!
Sandip Chitale’s Blog: LinearLayout gravity and layout_gravity explained
Sandip Chitale's Blog: LinearLayout gravity and layout_gravity explained.
Very helpful visualization of how gravity and layout_gravity play with each other.


