Droidin' out tips and tricks from an android expert

3Jan/120

How to Install Ice Cream Sandwich ROM on Motorola Droid X

Posted by noslen

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.

Filed under: android No Comments
27Nov/110

Hot Text is released!

Posted by noslen

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 :)

https://market.android.com/details?id=com.qtcstation&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5xdGNzdGF0aW9uIl0.

qrcode

cheers!

Filed under: android No Comments
17Nov/110

How To Properly Set SVN svn:externals Property In SVN Command Line

Posted by noslen

 

 

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!

Filed under: android No Comments
29Sep/110

Configuring Charles Web Debugger to work with Android devices and emulator

Posted by noslen

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)

Proxy settings on a Motorola Droid 3!!

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!

Eclipse run configuration settings.

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!

Filed under: android No Comments
5Sep/110

How to ensure views are set below the fold on a device.

Posted by noslen

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();

	    }
	});
Filed under: android No Comments
6Aug/110

Sandip Chitale’s Blog: LinearLayout gravity and layout_gravity explained

Posted by noslen

 

 

Sandip Chitale's Blog: LinearLayout gravity and layout_gravity explained.

Very helpful visualization of how gravity and layout_gravity play with each other.

Filed under: android No Comments
8Jul/110

Android bluetooth example

Posted by noslen

I'm starting more detailed work on Bluetooth sharing.
I found this snippet of code on the dev guide that looked very similar to a TCP socket which I did a while ago.
The code below is taken from :
http://developer.android.com/guide/topics/wireless/bluetooth.html

private class ConnectedThread extends Thread {
    private final BluetoothSocket mmSocket;
    private final InputStream mmInStream;
    private final OutputStream mmOutStream;

    public ConnectedThread(BluetoothSocket socket) {
        mmSocket = socket;
        InputStream tmpIn = null;
        OutputStream tmpOut = null;

        // Get the input and output streams, using temp objects because
        // member streams are final
        try {
            tmpIn = socket.getInputStream();
            tmpOut = socket.getOutputStream();
        } catch (IOException e) { }

        mmInStream = tmpIn;
        mmOutStream = tmpOut;
    }

    public void run() {
        byte[] buffer = new byte[1024];  // buffer store for the stream
        int bytes; // bytes returned from read()

        // Keep listening to the InputStream until an exception occurs
        while (true) {
            try {
                // Read from the InputStream
                bytes = mmInStream.read(buffer);
                // Send the obtained bytes to the UI Activity
                mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
                        .sendToTarget();
            } catch (IOException e) {
                break;
            }
        }
    }

    /* Call this from the main Activity to send data to the remote device */
    public void write(byte[] bytes) {
        try {
            mmOutStream.write(bytes);
        } catch (IOException e) { }
    }

    /* Call this from the main Activity to shutdown the connection */
    public void cancel() {
        try {
            mmSocket.close();
        } catch (IOException e) { }
    }
}

 

Filed under: android No Comments
7Jul/110

Lawrys Digital Dinner Bell – Android Market

Posted by noslen

My first major android app!

Over 10k downloads already!

Lawrys Digital Dinner Bell - Android Market.

Filed under: android, general No Comments
31May/111

android and JDK compliance – how to fix @override errors

Posted by noslen

 

 

From time to time when working with other people's projects I run into build errors that are caused by the @override annotation. It took me a while to understand why that was happening as I was usually able to solve it by simply deleting the @override annotation or adding it where needed.

an example of an error caused by @override

Turns out the problem is because of of a mismatch in the JDK different developers are using.

Starting in Java 6 the @override annotation no longer applies to interface methods. So most methods derived from an interface no longer need them. They are however needed with Java 5.  The problem arises if a dev with Java 5 creates an android project, By default the project will get set with whatever JDK compliance is valid in their environment, in this  Java 1.5. If a developer with java 6 opens the same project all  @override annotations will be flagged as errors when appearing above interface methods.

Thankfully, this is easy to fix.

You simply need to go to your android project properties, choose the java compiler and select the appropriate JDK compliance level for your environment.

Project Properties > Java Compiler

Click enable project specific settings to be able to select the appropriate JDK version to use.

Don't know which hava version you have? No problem. Simply type java -version in your command line to get that info. It will look like below

how to check your jdk version

Don't want to have to do this every time you and another developer have mismatching JDKs? You can configure it as a default on your workspace.

From the same Java Compiler properties window, click "Configure Workspace Settings"

That will bring you to the window below where you can choose your default Compiler compliance level for your JDK Compliance.

configure your default workspace settings

As per usual i'd like to thank the fine folks @ stackoverflow for their help.

Filed under: android 1 Comment
22May/110

Android units – pixels, density, dpi, dip, dp, dps, sp, sip | Edwin Evans

Posted by noslen

A bit more on dealing with android units.

Android units – pixels, density, dpi, dip, dp, dps, sp, sip | Edwin Evans.

 

 

Filed under: android No Comments