Upcoming features for Offline Logger v0.3

I thought I’d share the feature list / change log for the upcoming 0.3 update for Offline Logger.

Feel free to post any comments regarding it.

  • Confirmation when deleting history logs (prevents deletion by mistake)
  • Better graphics/UI in the History log.
  • Detailed information about a log (duration, amount of points, avarage logging interval, max/min speed, buttons to delete/share)
  • Add a help icon/popup to the menu to show some basic info.
  • Better UI and more information to the main logger view
  • Display a warning if GPS is disabled when starting the logger.
  • User configuration: Enable/disable autostart logger when application starts
  • User configuration: Enable/disable celltower position failover
  • User configuration: 12h/24h selectable time formatting in UI

No Comments

Offline Logger v0.2 + some battery stats

A bug was found. An embarassing one, but now it’s fixed and a new update is available on market!

The bug caused the history log-files not to be saved, which made the applications main-task to fail, but the fix was easy and now it’s working again. The reason was that the application tries to access the memory card to verify that it’s available and writable before starting a log (so you don’t log for 5 hours and then not possible to store the coordinates), but it created a file with the same name as the directory it tries to save the log-files to later, which made the directory creation to fail. A file and a directory with the same name cannot exist in the filesystem.

Many excuses to the affected people (probably <5 people since the application is new :) )

Battery statistics

I’ve been testing the application with 5seconds interval on a fully charged HTC Hero running Android 1.5. The results were pretty impressive, allthough I was running without a SIM-card and with wifi off (like airplane mode). It ran for about 12 hours, and then I turned it off manually, but it will run for an estimated 15 hours @ 5sec interval before battery is fully drained.

No Comments

Offline Logger v0.1 released

Offline Logger is now officially released on Android Market!

This is a FREE GPS Logger which does not use data/internet for anything. Good battery features such as disconnects the GPS for intervals on 30seconds or higher. Fallback to cell tower positioning if a real GPS Fix is not available within 10 seconds.

List of features:
* User changable interval
* Show history, delete or share logs
* Background service with wake-lock (works when display/phone is idle)
* Tested on Hero (Android 1.5) and Nexus One (2.1) with good results
* Fallback to celltower position when a real gps fix is not available within ~10seconds
* Information on amount of points in current history, and last update in UI

First release is available in English only, but in all countries.

Coming features:
* Homescreen widget for quick-starting/stopping a log
* Improved UI
* Sorting abilities in history
* View route on google maps (will require data/internet to load map)
* More configurations

Search for “Offline Logger” in android market, or scan this barcode to get started:
Search for Offline Logger on Android market.

No Comments

My apologies for the downtime, domain expired without my knowledge

My domain expired without my knowledge, the renewal notification e-mail from my registrar was filtered as spam by gmail so I missed it.

But lucky me I noticed just a few days after the expiration, so the grace period was still valid. Renewed and back!

I was actually first pissed off and thought my registrar didn’t notify me, and their domain-parking page looks like some crappy advertisement page so I thought anyone else had gotten their hands on it. A couple of e-mails later to the support and everything seemed to be fine, one day later (today) it’s back online. Thanks for the quick support/responses http://www.crystone.net

No Comments

How to create your own “Share” application for photos

This is alot easier to do than you might believe, it’s even so easy to do, that you might find it hard to find information about it in the documentation.

The main thing you have to do is to register your application to receive the SEND intent which is sent when clicking the “Share” button.

Add this to your Activity in the AndroidManifest.xml

<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <data android:mimeType="image/*" />
   <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Then you automatically get your application registered to the Sharing-list with the application name and icon, when selecting the application in the list, the activity will be launched and the photo is easily retreived through the launching intent.

final Intent intent = getIntent();
final Bundle content = intent.getExtras();
if ( content != null ) {
        //The uri below till contain an uri to the contentprovider
	final Uri uri = (Uri)content.getParcelable(Intent.EXTRA_STREAM);
 
        //if you want to know the filename of the image, just do a managedQuery 
        //against the projection MediaStore.Images.Media.DATA
}

No Comments

How to pull and install the dev-apps to your Android device

The emulator and some Android developer devices have some small util applications which could be to some help if you’re developing an application for an Android device. Looking at your production phone will reveal that you don’t have those pre-installed, but it’s easy to get them from an emulator and then install them to your real phone.

These apps will let you change and/or simulate a non-existing locale, view stacktraces from log-files, more detailed information about battery-usage, and so on…

Start by navigating to the tools directory within your Android SDK, then execute the following commands after you’ve started your emulator:

adb -e pull /system/app/CustomLocale.apk CustomLocale.apk
adb -e pull /system/app/Development.apk Development.apk
adb -e pull /system/app/SpareParts.apk SpareParts.apk

That will retreive the packages for the three applications CustomLocale, DevTools and SpareParts from the connected emulator.

Then connect your device with the USB-cable if it’s not already plugged in and execute these commands from the same location:

adb -d install CustomLocale.apk
adb -d install Development.apk
adb -d install SpareParts.apk

Then you’ll have the three utils installed to your phone, ready to use.
Please note that everything might not work if you don’t have a real developer device, or running on a non-rooted device, some features might crash while trying to use them.

No Comments

How to prevent setting dynamic fields in your PHP classes

One problem that could arise when multiple coders are working on the same project is that everyone might not work with the same editors, and therefore everyone might not have intellisense / autocompletion. What could this cause? Alot of things :) But we’ll talk about one of them below.

Well all PHP classes are by nature dynamic, which means that it’s possible to set variables that havn’t been declared. One would believe that setting the class to “final” would automatically fix this, but this is not the case.

Simple example:

class SimpleStructure 
{
	public $name;
	public function __construct( $name ) {
		$this->name = $name;
	}
}
 
$simple = new SimpleStructure("nonobtrusive");
$simple->myName = "dynamic_value";	//allowed
 
echo $simple->name, " - ", $simple->myName;

The above code will output:

nonobtrusive - dynamic_value

So, how can we prevent this if it’s an unwanted behaviour ?
The answer is simple, use the magic method __set.

class SimpleStructure 
{
	public $name;
 
	public function __construct( $name ) {
		$this->name = $name;
	}
 
	public function __set( $key, $value ) {
		throw new Exception( "Not allowed to assign undefined variable : " . $key );
	}
}
 
$simple = new SimpleStructure("nonobtrusive");
$simple->myName = "dynamic_value";	//allowed
 
echo $simple->name, " - ", $simple->myName;

The above code would throw the error:

Fatal error: Uncaught exception 'Exception' with message 'Not allowed to assign undefined variable : myName'

To wrap this up we could also create our own UndefinedFieldException class and throw an instance of it to easier catch that specific error.

class UndefinedFieldException extends Exception
{
	public function __construct( $key ) {
		$this->message = "Not allowed to assign undefined field : " . $key;
	}
}
 
//then we can throw the exception like this instead
throw new UndefinedFieldException( $key );
 
//which in the above example would show as
Fatal error: Uncaught exception 'UndefinedFieldException' with message 'Not allowed to assign undefined field : myName'

, , , , ,

1 Comment

Wan’t to get rid of your traces to trace? (Flex)

Update: to clearify I want to mention already here that this post regards using the Flex SDK, since the Adobe CS have an “Omit traces” checkbox which totally removes all traces in the bytecode as well.

I noticed a high FPS-loss in one of my applications when testing some Z-sorting in the Flash 10 3D functionality which I hadn’t been seing before. This even when using release mode when compiling! I had to use the profiler through Flash Builder 4 beta to track it down to a trace in the Z-ordering algorithm (just using a regular Painters Algorithm based on the actual Z-value compared to the root). /Update

What’s up with that trace draining performance even when compiling in release mode?

Believe it or not, but the bytecode regarding traces look identically no matter if you use release or debug compilation mode, it’s just up to the flashplayer itself to actually make something with the call to trace depending on the release mode.

So here’s the proof, and solution:

A normal constructor for a Main class:

public function Main():void 
{
	trace("Test");
}

So, you’re running your little flash-application in debug mode while developing, of course because you want to see the trace messages. But what happens behind the scene?
This is what the ABC2 byte-code looks like for the above Main constructor, notice the trace with 13, 15 and 17 in front (which by the way is the sum of instructions for the AVM2 engine).

function Main():void	/* disp_id -1*/
{
	// local_count=1 max_scope=1 max_stack=2 code_len=24
	0       debugfile     	"E:\temp\TraceTest\src;;Main.as"
	2       debugline     	13
	4       getlocal0     	
	5       pushscope     	
	6       debugline     	13
	8       getlocal0     	
	9       constructsuper	(0)
	11      debugline     	15
	13      findpropstrict	trace //find the trace function
	15      pushstring    	"Test" //the string to trace
	17      callproperty  	trace (1) //call the function
	20      pop           	          //end - start of next, 20-13 = 7 instructions for the AVM2 engine
	21      debugline     	16
	23      returnvoid    	
}

Okay, nothing weird here since its compiled with debug, but what really happens when we switch to release mode?
Well, mainly the compiler will remove the debugline, telling what line in the actual source-code (.AS files) the flashplayer executes the code for. This is the information shown in unhandled exceptions that gets thrown so you easily can find the broken code.

But, what about that trace?

This is the exact same code, only switched to release mode:

function Main():void	/* disp_id -1*/
{
	// local_count=1 max_scope=1 max_stack=2 code_len=13
	0       getlocal0     	
	1       pushscope     	
	2       getlocal0     	
	3       constructsuper	(0)
	5       findpropstrict	trace //Didn't I just tell you to go away by switching to release mode?
	7       pushstring    	"Test" //Even the strings are left intact
	9       callpropvoid  	trace (1) //And also the function call.... sigh
	12      returnvoid    	     //still adding upp to 12-5 = 7 instructions as well since it's the exact same code
}

But how can we solve this?
One solution could be to add a global flag in the main class and then use it as condition when to use the trace

private const DEBUG:Boolean = false;  //change to true when developing

But this would only make the release build to evaluate that flag to see if we want to trace or not,
so how about removing all traces by hand ? Not too funny when we want to continue to develop again.

The solution is called conditional compilation and is supported by the Flex compiler.
See Adobes reference here: http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html

The solution for this example:

public function Main():void 
{
	IFDEF::DEBUG {
		trace("Test");
	}
}

And by passing this to the compiler:

-define=IFDEF::DEBUG,false
//or
-define=IFDEF::DEBUG,true

we simply make the compiler remove the whole block of code within the { } when IFDEF:DEBUG is set to false

This produces the ABC2 byte-code as follows, nice and clean from the trace:

function Main():void	/* disp_id -1*/
{
	// local_count=1 max_scope=1 max_stack=1 code_len=6
	0       getlocal0     	
	1       pushscope     	
	2       getlocal0     	
	3       constructsuper	(0)
	5       returnvoid    	
}

, , , , , ,

4 Comments

Array clone in javascript ?

There’s no such thing unfortunately, but it’s easy to replicate the same behaviour since we’ve got a handy cross-browser method called slice.
So what does the slice method do ? It allows up to two parameters to be passed in, start index and end index. If none are sent in the slice method will return a COPY of the original array, which allows us to use it as if it were a clone method. If only the first parameter is specified it will assume the full length of the array as secondary parameter. Not specifying a value will as earlier mentioned behave the same as this:

var copiedArray = theArray.slice( 0, theArray.length );
 
//this results in the same
var copiedArray = theArray.slice();

Examples:

var sourceArray = [1,2,3,4,5],
     clonedArray = sourceArray.slice();
 
alert(sourceArray.slice(1));  //will return & alert a copied array with the values 2,3,4,5 at indexes 1,2,3,4
 
alert(sourceArray.slice(1,2));  //will return & alert a copied array with the value 2 at index 0
 
sourceArray = sourceArray.slice(1,4);  //sourceArray will now contain 2,3,4
 
alert(clonedArray);  //will still alert 1,2,3,4,5 since it's a copy of the original array and not a reference.

No Comments

“Keeping” calling-context with setTimeout/setInterval

The javascript setTimeout function allows to pass some code or function to be called after a specifiec timeout in milliseconds. But since the callback is handled by the Window object it’ll loose the “this” from whatever it was called from. There’s two possible solutions to this, the first and most common is to use something like

var self = this;
setTimeout( function(){
     self.someValue = ........;
     self.someFunction();
     etc....
}, 500 );

But one other option is to execute the anonymous function which then returns another function as the code below shows.

function Foo(){
	setTimeout( (function(self){
		return function(){
			alert(this);	//Window
			alert(self);	//Foo
		}
	})(this), 2500 );
}
Foo.prototype.toString = function(){
	return "[object Foo]";
}
new Foo();

, ,

No Comments