Monday, December 15, 2008

TraceView : the Android profiler ?

Yesterday, I tried to use the Android profiler, traveView.

I carefully added a Debug.startMethodTracing("MyGame") and a Debug.stopMethodTracing() at the start and at the end of my activity, check that I had a file with a non zero length ( I hadn't that at the start ).

So I happily launch
traceview.bat c:\work\temp\MyGame.trace

How deceive I was to have such a result, instead of a nice graphic application !

Exception in thread "main" java.lang.RuntimeException: Method exit (java/lang/Object. ()V) does not match current method (java/lang/reflect/Constructor.constructNative ([Ljava/lang/Object;Ljava/lang/Class;[Ljava/lang/Class;IZ)Ljava/lang/Object;)
at com.google.traceview.ThreadData.exit(ThreadData.java:116)
at com.google.traceview.ThreadData.handleCall(ThreadData.java:78)
at com.google.traceview.DmTraceReader.parseDataPass2(DmTraceReader.java:285)
at com.google.traceview.DmTraceReader.parseData(DmTraceReader.java:176)
at com.google.traceview.DmTraceReader.generateTrees(DmTraceReader.java:78)
at com.google.traceview.DmTraceReader.(DmTraceReader.java:71)
at com.google.traceview.MainWindow.main(MainWindow.java:187)

I though it might be because of the path, so I put my trace file in my tool directory... Same results...

In the documentation, they don't use the .trace extension... With no hope I tried it... But it didn't change anything...

So for the moment, I have no solution.
On the forums, someone suggested that the profiler was simply not working on XP...
Well, I don't know.

if someone has a suggestion, I'd happily heard it !

Tuesday, December 9, 2008

How to deal with different Android Phone resolutions ?

Hi all, 


Now that Kogan will soon (?) release a new Phone ( Agora ), we should not limit our application to the T1 presets.

In peculiar, it looks like this phone will have a different resolution. It will be a QVGA one ( 320 x 240 pixels )  ( the T1 is 480x800).

The simplest way to deal with different resolution seems to handle different xml files for each resolution !

So we can have a res/layout-320x240 file and a res/layout-640x680 one, etc...

It let you have an acute control on your design, while still maintaining a common code.

Last note : it is not limited to layout, you can specify all of your resources, like drawable !




Friday, December 5, 2008

Issues with ListViews, at last solved !!

Hi all, 

At least after trying all the android parameters, I found the correct one to fix my issue !

It was the cacheColorHint, that was to be set to #00000000 !

I tried this :


android:textColorPrimary="#FF112233"
android:textColorPrimaryDisableOnly="#FF112233"
android:textColorPrimaryInverse="#FF112233"
android:textColorPrimaryInverseNoDisable="#FF112233"
android:textColorPrimaryNoDisable="#FF112233"
android:textColorSecondary="#FF112233"
android:textColorSecondaryInverse="#FF112233"
android:textColorSecondaryInverseNoDisable="#FF112233"
android:textColorSecondaryNoDisable="#FF112233"
android:textColorTertiary="#FF112233"
android:textColorTertiaryInverse="#FF112233"
android:listSelector="@android:color/transparent"
android:drawSelectorOnTop="false"

that failed miserably, and this single line just saved my day :


android:cacheColorHint="#00000000"

Ok, good to know...
I just feel like the documentation was a little light on this subject.
There are so many parameters, and this one does not look like the more intuitive to change for my problem.

Ok, that's done, that will be enough for today !

Wednesday, December 3, 2008

problem with a ListView


I am stuck with a aesthetic issue with List Views for several days, and I can't find any solution.

So, as a very experimented programmer as I am, I'm gonna use a very advanced technique : ask for any solution for this problem publicaly !
Usually, some seconds after warning the whole planet, the programmer finds the solution on his own !


Here's my problem :
I have a ListActivity, with my list of High Scores :


Score List on My Android Phone

But the problem arises when I click on the listView to make it scroll :

Google Android Phone Emulator View

It is less sexy this way ( and also quite less readable ).

I tried to juggle with some parameters, like enable / clickable / focusable / focusableInTouchMode (that I just understood from the http://android-developers.blogspot.com/ site). I also tried the listSelector or the background parameters ; but with no success...

I'm sure there is something I miss there, but what...


( Note : I have now found the solution here )




Sunday, November 9, 2008

EditText with limited number of characters

I just fough with the SDK for quite some time to find this one.

As a average modern programer, I started by looking on the internet, but didn't find anything. I imagine I didn't search the right sites ( no comments on this please ! )

So this is what I came up with :


editEntryView.setOnKeyListener
(
new View.OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
EditText NameView = (EditText ) editEntryView.findViewById( R.id.PlayerName );
String Name = NameView.getText().toString();
if ( Name.length() >= 8 )
{
if ( keyCode != KeyEvent.KEYCODE_DEL )
return true;
}
return false;
}
}
);

I imagine that there are many things that should be cleaner here, but, hey !, it works, and that so good for me !

I fought for some time, because I was looking for a way to call a parent method when I didn't treat the case and decided to pass for this letter.
Actually, the behaviour is just the opposite :
if you return true, it means you dealed with the entry, so the treatment will stop here.
if you return false, it means you didn't deal with the entry, so it will be passed to the next listener.

Actually, a classic listener pattern !



Next thing : enter as a ok-click entry !