Skip to Content

Blog

Android studio hangs “Waiting for ADB”

I have been getting android studio hangs intermittently (whole window frozen) and it looks to just be ADB hanging. Seems to happen a lot when my mac sleeps.

The solution was just to restart adb using :
adb kill-server; adb start-server

Hopefully this will be fixed soon. the whole Android studio inferface shouldn’t hang just because ADB isn’t responding – it should be in a background task.

Hope it helps someone.

Recover files from a non booting device

This is for when you have not been able to boot your phone and need to get files off it.
The device (a Nexus 4) turns on but never makes it past the loading screen.
So it doesn’t finish booting – but mine had booted enough to have ADB running.

To use this method you need to have ADB installed on the host. (e.g. install dev tools – see [1])

* To get the list we use ADB shell
$ adb shell
shell@mako:/ $ ls /sdcard/                                                     
...    
DCIM/                                 
shell@mako:/ $ ls /sdcard/DCIM/                                                
100ANDRO/                 Camera/                 

shell@mako:/ $ ls /sdcard/DCIM/Camera/        
... (list files)

* Take this list (select+copy) and paste to to a local file say picnames.txt
* Then execute
$ cat picnames.txt | xargs -I % adb pull /sdcard/DCIM/Camera/%
7003 KB/s (3677132 bytes in 0.512s)  ...

This should copy the files to the local directory … phew!

refs:
[1] http://developer.android.com/sdk/index.html

Some great in depth turtorials and slide for Android tasks

These are some great tutorial/slides I found recently:

Threading:
http://www.slideshare.net/andersgoransson/efficient-android-threading

Loaders:
http://www.slideshare.net/cbeyls/android-loaders-reloaded

Android source:

Setting up Junit ServiceTestUnit tests with Application references

I have been setting up unit testing for an existing project of late and when testing services I ran into problems setting up the application and base context references. Searching around – I wasn’t able to find a way to do this, hence I am noting it down to make it (hopefully) easier for you..

Setting the Application context in the test unit setUp() enabled me to get the Application object but many other calls did not work (e.g. getPackageName()). To properly setup the application object we need to set the Base Context for the application object. This can be done by overriding attachBaseContext(Context base) in the application object and making it public.

Of course you shouldn’t really have to change your source to run tests – but in practice it happens anyways (e.g. making methods public to call them from the test).

Application

This method is added to the application object it overrides the default from ContextWrapper
        @Override
	public void attachBaseContext(Context base) {
		super.attachBaseContext(base);
	}

DownloadServiceTest

public class DownloadServiceTest extends ServiceTestCase<DownloadService> {
	DownloadService _downloadService;
	public DownloadServiceTest() {
		super(DownloadService.class);
	}
	public DownloadServiceTest(Class<DownloadService> activityClass) {
		super(activityClass);
		
	}

	protected void setUp() throws Exception {
		super.setUp();
		MyPODApplication myPODApplication = new MyPODApplication();// the application object
                // the overrided method to attach the context - we pass the Context provided by getSystemContext();
		myPODApplication.attachBaseContext(getSystemContext());
		setApplication(myPODApplication);
		
	        getApplication().onCreate();
	        setContext(getApplication());
	    
		Intent i = new Intent(getSystemContext(),DownloadService.class);
		i.setAction(Globals.INTENT_START_DOWNLOADS);
		Log.d(DownloadService.class.getSimpleName(), "dl svc started");
		startService(i);

                 // should use a service binder here
		_downloadService = getService();  
	}  
        // more test methods here
}

Using CSS precedence

I have been coming back to HTML / CSS lately and I came across errors where my CSS would not be overridden. Then I found this very good article on CSS Precedence by Steven Bradley.

http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/

This article gives a thorough understanding of CSS Precedence, and is well considered looking at the comments …

The thing I got from it was that it is probably better to design your HTML with pseudo tags, as those styles will always give the lowest precedence. Then base styles can then be overridden more easily by giving class (0 0 1 0) or id (0 1 0 0) attributes to elements. This should give the greatest flexibility in correcting errors, and creating re-useable CSS.

Using !important should not be necessary in well designed CSS. They can be handy in a quick spot I guess – but long term they just make the CSS harder to edit.

W3 ref: http://www.w3.org/TR/CSS2/cascade.html

Fixing performance issues in Ubuntu 12.10

I bought a new computer last year and it has been running rather slow since install. Just wanted to go through the journey which has been a relief to get fixed.

Finding a good profiler

I found “System profiler and benchmark” (http://hardinfo.berlios.de/HomePage). Which found some interesting results for CPU performance (the command line tool lscpu does the same thing). The processor is a quad core 3.4GHz processor so the intro screen looks fine. But the processors section shows that the processors aren’t running at full speed (the second image below).

Intro screen

Screenshot from 2013-06-20 09:21:18

Processor info

Screenshot from 2013-06-20 09:21:08

Processor info


This is confirmend using lscpu
$lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    2
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 42
Stepping:              7
CPU MHz:               1600.000
BogoMIPS:              6784.14
Virtualisation:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              8192K

Solution – Granola

After a bit of searching around I found this post). Which points me to Granola some nice power saving software which controls CPU frequencies. The client software monitors how much power is being used (below). And give an overview of power savings – this data feeds into the project website to show how much power the software is saving globally.

Screenshot from 2013-06-20 09:34:19

Installation

Installation is quite simple, the instructions are for Quantal :

  1. Check you are running Quantal (The links below are for that release – 12.10 Quantal) (running lsb_release -a)
  2. Download the DEBs: granola_5.0.15-0quantal1_amd64.deb, granola-gui_5.0.15-0quantal1_amd64.deb
  3. Install the debs, I just click on them but you can use sudo dpkg -i granola_5.0.15*.deb in the download directory to install form the command line).
  4. To start granola run it as root (sudo granola)
  5. You can launch the GUI program which is installed in Accessories > Granola
  6. Edit > Preferences > Switch to “Highest Power” (see screen below)

Unfortunately to fix my problem I need to set my computer to highest power – which isn’t really in the spirit of the project – but the GUI tool and associated software do give the the option to change the settings at will. So as long as I remember to switch over then there are still contributions to be made.

Screenshot from 2013-06-20 09:34:24

Afterwards, lscpu shows a better result:

$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    2
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 42
Stepping:              7
CPU MHz:               3401.000
BogoMIPS:              6784.14
Virtualisation:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              8192K
NUMA node0 CPU(s):     0-7

Not using swap space?

https://help.ubuntu.com/community/SwapFaq

checking memory type

http://www.crucial.com/store/listmodule/DDR3/list.html $ sudo dmidecode –type memory # dmidecode 2.11 # SMBIOS entry point at 0xbab5ed98 SMBIOS 2.6 present. Handle 0x000F, DMI type 16, 15 bytes Physical Memory Array Location: System Board Or Motherboard Use: System Memory Error Correction Type: None Maximum Capacity: 8 GB Error Information Handle: Not Provided Number Of Devices: 2 Handle 0x0011, DMI type 17, 28 bytes Memory Device Array Handle: 0x000F Error Information Handle: Not Provided Total Width: 64 bits Data Width: 64 bits Size: No Module Installed Form Factor: DIMM Set: None Locator: DIMM1 Bank Locator: BANK0 Type: Unknown Type Detail: Synchronous Speed: Unknown Manufacturer: A1_Manufacturer0 Serial Number: A1_SerNum0 Asset Tag: A1_AssetTagNum0 Part Number: Array1_PartNumber0 Rank: Unknown Handle 0x0013, DMI type 17, 28 bytes Memory Device Array Handle: 0x000F Error Information Handle: Not Provided Total Width: 64 bits Data Width: 64 bits Size: 4096 MB Form Factor: DIMM Set: None Locator: DIMM3 Bank Locator: BANK2 Type: DDR3 Type Detail: Synchronous Speed: 1333 MHz Manufacturer: Samsung Serial Number: 232E6316 Asset Tag: A1_AssetTagNum1 Part Number: M378B5273DH0-CH9 Rank: 2

Weekly issues of interest

These were some of the bugfixes I had this week – that took a little while the get around, just because they were a bit less obvious.

Dont re-use RemoteViews in widgets

This causes each action applied to applied each time – for a RemoteViews object in a widget create a new instance each time – I had some large memory leaks due to strings being held in a re-used RemoteViews object.

https://groups.google.com/forum/?fromgroups#!topic/android-developers/qQ4SV5wL7uM

Making a StateListDrawable: ordering the states are added is important.

When making a StateListDrawable in code, the order that the states are added determines the evaluation order – the statelist drawable then sets the first state it sees above or equal to the level of the state. In the two examples examples, the top one works, but below the drawable will always display enabled (1) if the enabled drawable is added first (i.e. it appears not to reflect the states at all).

The code below displays the states correctly:

StateListDrawable sld = new StateListDrawable();
sld.addState(new int[] { android.R.attr.state_selected },mSelectedDrawable);
sld.addState(new int[] { android.R.attr.state_pressed }, mPressedDrawable);
sld.addState(new int[]{android.R.attr.state_enabled},  mEnabledDrawable);// enabled (1)
sld.addState(new int[]{-android.R.attr.state_enabled}, mDisabledDrawable);//disabled

The next code below always displays the enabled state, as the enabled level is low(1), but is added first in the execution order.

Presumably the states are added to an internal array and so the first state that satisfies the StateListDrawable’s current state is used (i.e. even if its selected it is also enabled and because enabled is added before the selected state, the enabled drawable is used)

StateListDrawable sld = new StateListDrawable();
sld.addState(new int[]{android.R.attr.state_enabled},  mEnabledDrawable);// enabled (1)
sld.addState(new int[] { android.R.attr.state_selected },mSelectedDrawable);
sld.addState(new int[] { android.R.attr.state_pressed }, mPressedDrawable);
sld.addState(new int[]{-android.R.attr.state_enabled}, mDisabledDrawable);//disabled

Flyin menu using offsetLeftAndRight not preserving after a layout

While making the flyout menu for the new MyPOD I encountered a little bug that I couldn’t find an answer for.

The problem ..

I was using offsetLeftAndRight to hold the flyout “open” after the animation finishes (simply using fillAfter on the animation produces and annoying flicker). This method takes a "relative" amount to move (i.e. the amount to offset the view from it’s current position). So this container hold whatever content might be in the front screen. But the problem was that whenever a child in this container called requestLayout. the offset would be wiped, and so the flyout would appear to suddenly close.

The API >10 solution

HoneyComb added the onLayoutChangeListener which makes it really easy to restore the old value, it is just provided in the method call.

if (Build.VERSION.SDK_INT>10) {
			_contentContainer.addOnLayoutChangeListener(new OnLayoutChangeListener() {
				
				@Override
				public void onLayoutChange(View v, int left, int top, int right,
						int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
					_contentContainer.offsetLeftAndRight(oldLeft);
				}
			});
		}

And for the rest … API<=10

Without the layout change listener the only way I could think of to react to layout changes was to use tried and true override of the onLayout method. So the container class (RelativeLayout) was extended. This sets the accumulated value when the reset condition is detected (left==0 && left != _accumOffset). There may still be problems for other use cases, but for me it has the desired effect of preserving the open state of the flyout on all API Levels.

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

public class RelativeLayoutPreserveOffset extends RelativeLayout {
	int _accumOffset=0;
	
	public RelativeLayoutPreserveOffset(Context context, AttributeSet attrs,	int defStyle) {
		super(context, attrs, defStyle);
	}

	public RelativeLayoutPreserveOffset(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public RelativeLayoutPreserveOffset(Context context) {
		super(context);
	}

	@Override
	public void offsetLeftAndRight(int offset) {
		_accumOffset+=offset;
		super.offsetLeftAndRight(offset);
	}

	@Override
	protected void onLayout(boolean changed, int left, int t, int r, int b) {
		if (left != _accumOffset) {
			if ( left == 0 ) {
				super.offsetLeftAndRight(_accumOffset);
				super.onLayout(changed, _accumOffset, t, r, b);
			} else {
				_accumOffset=left;
				super.onLayout(changed, left, t, r, b);
			}
		} else {
			super.onLayout(changed, left, t, r, b);
		}
		
	}
}

MyPOD re-write, vector graphics improvements & DroidCon

MYPOD re-write is on

The MyPOD re-write has started in earnest – we are working with some high caliber UX / UI specialists to make this full upgrade something special.

We have been putting out feelers with some users about the new design and the feedback has been great. So watch this space for some great news over the next couple of months. This re-write will address the usability bugs that some have complained about, as well as strengthen & make the app features easier to find and use.

Vectoroid SVG improvements

As part of the MyPOD re-write there have been a number of improvements in the Vectoroid library. Those pesky Arc’s are fully functional, and support will be in the upcoming release (0.83) in a couple of weeks.

Also coming in the next version are SVG drawables – These can be used in any android component that takes a drawables (which is anything). There are still a few kinks to iron through – but it works, and they are crisp … No more will I make 4 versions of each icon.

DroidCon London

Droidcon London, Oct 6-7

http://uk.droidcon.com/

The 2012 DroidCon is almost upon us. It is really getting bigger every year and this year looks to be no different.

Talks on Android x86, AndEngine, AI, Animations, Custom components and Google TV are the subjects that I am looking at. I may even sneak in a BarCamp talk on Vectoroid. Hope to see you there.

Patenting tap to zoom is like patenting DNA


Yes, Apple you won. I would say that a number of people told me that they bought a galaxy S2 cos it looked "a bit" like and iPhone. So there is some merit to that aspect …



But, where are we heading? Using these patents to wage war with – they are so basic if companies and patent trolls let rip with some of these then we are all in trouble…

Tech evolves quickly. In some ways there is a lot of evidence that the first mover is not always the ultimate winner. But Android AND Apple have created cultures and to subject actual users to limits on these simple functions isn’t an option – it all about getting da monay.

Weather they like to acknowledge it or not, they are creating a space together – people passionate about iPhone – people passionate about Android.


This, right here, is the danger of software patents. When obvious things (that generally come up in user testing – i.e. testing what feels *natural* to a user). Denying tap to zoom (and pinch to zoom? not sure on this) as a natural part of tech progression is in some ways like patenting DNA because they were just testing what feels natural for the user – probably other testing found the same thing – just because Apple did it a bit before shouldn’t give them global rights to it. Some of the knowledge captured in these patents should possibly be public domain as it relates to all of us.

The other patents are equally as obvious.

( source : http://www.bbc.co.uk/news/technology-19377261 )


There is definitely a moral imperative here not to hamstring each other – this will not only stifle innovation for manufacturers, but also for app developers… These patents really should have been invalidated by now – but because it takes so long to grant them, most of them have only been approved for a couple of years. Speeding up the award and invalidation cycle may be an improvement for the patent system. But the legal precedents set here are very worrying …


Mind, these patents should these never have been awarded as the usage has fallen into common use by the time the patent is awarded. Now we have to wait and hope that governments will realise the dangers of an ineffective patents system and reform it – I can’t say I’m holding my breath though …