Archives for 23 Aug,2010

You are browsing the site archives by date.

Nexus one 2600mAh high capacity battery replacement

I have a nexus one which has comparatively decent battery life to other smart phones, lasting about 1 day with casual usage. The battery that comes with the nexus one is 1400mAh, but I noticed dealextreme are selling a 2600mAh replacement battery.

Nexus one high capacity battery (2600mAh)

Nexus one high capacity battery (2600mAh)

The battery costs $14.00 (£8.81) which will give an extra 85% increase in charge. This means the that my nexus one should last closer to 2 days with casual use now, I have ordered one and will update with some benchmarks when it arrives (unfortunately not in time for my camping weekend).

Read More

Making Prettier Buttons in android; XML (rollover,selection & focus effects), 9patch images and transparency

Alot of the soundboards out there on the market look a little bit ugly by using the default android buttons in conjunction with a background (no offense to developers of these, perhaps they can learn from this); this mini-tutorial explains how to use xml to create a customised nice looking button thing.

Ugly Buttons:
Below is show the example I will use to demonstrate the default buttons in use with a background image (It’s a picture of me hugging the android statue!)

"Ugly" default buttons in android

Button States

There are four images you will need to create (you can use less if you want); one for each of the following states:

state_focused state_pressed What this means
true false Button highlighted (selected with trackpad)
true true Button foussed and pressed
false true Button pressed
false false Normal state of button

I recommend creating a nine-patch png for the button image, this way your image can be stretched to fit the button size as needed. Also soundboards look rather snazzy if you include a background image, and then you can use transparency in your png so that your buttons don’t obscure it.

draw9patch tool button android

Using draw9patch tool to make a 9patch png for use as a strechable button

XML Code

button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true"
	android:state_pressed="false" 
	android:drawable="@drawable/button_selected" />
    <item android:state_focused="true" 
    	  android:state_pressed="true"
    	  android:drawable="@drawable/button_focus" />
    <item android:state_focused="false" 
    	  android:state_pressed="true"
	  android:drawable="@drawable/button_pressed" />  
    <item android:drawable="@drawable/button_normal" />
</selector>

main.xml
An example usage of how to use this newly created xml button in your layout file.

<Button
android:id="@+id/mysexynewbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textStyle="bold"
android:text="Stealthcopter FTW"
android:background="@drawable/button" />

Results
Now you should have some nice sexy customised buttons that change depending on thier state. Which makes our example now look like this (I increased the padding and margins of the buttons slightly):

Pretty Buttons with transparency using 9patch png and xml

Pretty Buttons with transparency using 9patch png and xml

Below are a few examples of my work with some nice transparent buttons:

Example 9 patch image

button.9.png

button.9.png

Read More