Archive for December, 2011

[Android] how to include your app into list in dialog which is launched when you put device on cradle or dock

Saturday, December 10th, 2011

I am very in trouble not to find how to solve the problem.
The problem is that I want to include my app into list in dialog.
The dialog is launched when I put device on cradle or dock.

I have searched for a very long time.
And finally I found it!

The hint page is here. I appreciate the author writing it very much.
Custom CAR DOCK application in Android

I have to use intent. And the setting is following.

AndroidManifest.xml

            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DESK_DOCK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

This resolve point is I have to use both category.DESK_DOCK and category.DEFAULT together.
If I use only which one of those, it can’t work.

Here is the screenshot.
DeskDockTest app is my application.
The others are default app of devices.

[Javascript] jQuery mielogger Plugin : Make Any Log Visible

Friday, December 2nd, 2011

I made a jQuery plugin named mielogger.

This makes any string you set visible on browser.
It was named from mieru (it means ‘you can see’ in Japanese ) and logger.

It is very useful tool, when you develop mobile browser app such as iOS, Android, etc.
Because those devices can’t be shown console.log() function.
But if log is visible in browser, you can see it.

update Dec. 10th 2011

>> demo
>> download mielogger

how to use

First, you must import jQuery and mielogger.js.

	<script src="jquery-1.6.2.min.js"></script>
	<script src="mielogger.js"></script>

Seccond, init mieLogger.

var logger = $().mielogger();

Third, you can write any string on it with log method.

logger.mlog('Hello mielogger');

I used mielogger’s instance on the last code. But you can also use this way.

$().mlog("It's OK");

option settings

You can set options to it when you init it.

There are some parameters.

width : log area width
height : log area height
maxlow : max log line length. mielogger can hold lines over the height of it
align : if it is set, log area’s layout is changed.
‘TL’ top left
‘TR’ top right
‘BL’ bottom left
‘BR’ bottom right

example1: width 300px, height 100px

$().mielogger({width:300,height:100});

example2: width 450px, maxlow 100

$().mielogger({width:450,maxlow:100});

example3: align BL

$().mielogger({align:'BL'});

Let’s log it.

[JavaScript] Asynchronous library in Javascript

Thursday, December 1st, 2011

I wrote asynchronous JavaScript library.

Here is the code.

if(!window.kinkuma){
	window.kinkuma = {}
}
(function(pkg){
	/**
	 * Command - base class
	 */
	pkg.Command = function(){
		this.delegate;
	};
	pkg.Command.prototype = {
		execute:function(){
		},
		onComplete:function(){
			if(this.delegate){
				this.delegate();
			}
		}
	}
	
	/**
	 * FuncCommand - function command
	 * @param func Object - function reference you want to run
	 */
	pkg.FuncCommand = function(func){
		this.targetFunction = func;
	};
	pkg.FuncCommand.prototype = new pkg.Command();
	pkg.FuncCommand.prototype.execute = function(){
		this.targetFunction();
		this.onComplete();
	};
	
	/**
	 * WaitCommand - timer command
	 * @param waitTime Numer - it's not milliseconds but second
	 */
	pkg.WaitCommand = function(waitTime){
		this.waitTime = waitTime;
		this.timerId;
	};
	pkg.WaitCommand.prototype = new pkg.Command();
	pkg.WaitCommand.prototype.execute = function(){
		var self = this;
		this.timerId = setTimeout(function(){self.onComplete();}, this.waitTime * 1000);
	};
	
	/**
	 * ParallelCommand - run all commands together
	 */
	pkg.ParallelCommand = function(){
		this.commands = [];
		this.count;
	};
	pkg.ParallelCommand.prototype = new pkg.Command();
	pkg.ParallelCommand.prototype.execute = function(){
		if(this.commands.length == 0){
			this.commands = [];
			this.onComplete();
		}else{
			this.count = 0;
			var i, len;
			len = this.commands.length;
			var command;
			var self = this;
			for(i = 0; i < len; i++){
				command = this.commands[i];
				command.delegate = function(){self.commandComplete()};
				command.execute();
			}
		}
	};
	pkg.ParallelCommand.prototype.add = function(command){
		this.commands.push(command);
	};
	pkg.ParallelCommand.prototype.commandComplete = function(){
		this.count++;
		if(this.count == this.commands.length){
			this.onComplete();
		}
	};

	/**
	 * SerialCommand - serial run command
	 */
	pkg.SerialCommand = function(){
		this.commands = [];
		this.currentCommand;
	};
	pkg.SerialCommand.prototype = new pkg.Command();
	pkg.SerialCommand.prototype.execute = function(){
		if(this.commands.length == 0){
			this.onComplete();
		}else{
			this.currentCommand = this.commands.shift();
			var self = this;
			this.currentCommand.delegate = function(){self.commandComplete();};
			this.currentCommand.execute();
		}
	};
	pkg.SerialCommand.prototype.add = function(command){
		this.commands.push(command);
	}
	pkg.SerialCommand.prototype.commandComplete = function(){
		this.currentCommand = null;
		this.execute();
	};
})(kinkuma);

Usage

This function named 'trace' is used with these usage. It's not so important.

function trace(message){
	console.log(message);
}

Let's start it.

WaitCommand
It's a timer class.

var mywait = new kinkuma.WaitCommand(1.0);
mywait.execute();

You can add callback function.

var mywait2 = new kinkuma.WaitCommand(2.0);
mywait2.delegate = function(){
	trace('mywait2 finished');
};
mywait2.execute();

FuncCommand
It's function command. You have to input function reference to constructor's argument.

var myfunc = new kinkuma.FuncCommand(function(){
	trace('myfunc done');
});
myfunc.execute();

You can add callback function.

var myfunc2 = new kinkuma.FuncCommand(function(){
	trace('myfunc2 done');
});
myfunc2.delegate = function(){
	trace('myfunc2 complete');
};
myfunc2.execute();

ParallelCommand
These commands will start in the same time.

var k = kinkuma;
var para = new k.ParallelCommand();
para.add(new k.WaitCommand(1.0));
para.add(new k.FuncCommand(function(){trace('para func1');}));
para.delegate = function(){ trace('finish para');};
para.execute(); 

SerialCommand
Serial execute commands.

var k = kinkuma;
var sc = new k.SerialCommand();
sc.add(new k.WaitCommand(0.5));
sc.add(new k.FuncCommand(function(){trace('seri func1');}));
sc.add(new k.WaitCommand(3.0));
sc.delegate = function(){trace('finish serial');};
sc.execute(); 

Parallel and Serial Mix in
It's very interesting time. You can mix with ParallelCommand and SerialCommand.

var k = kinkuma;
var p = new k.ParallelCommand();
p.add(new k.FuncCommand(function(){
	trace('para func1');
}));
p.add(new k.FuncCommand(function(){
	trace('para func2');
}));
var s = new k.SerialCommand();
s.add(new k.WaitCommand(1.0));
s.add(p);
s.delegate = function(){
	trace('mix finish!');
};
s.execute();

I referred to below ActionScript3 codes in Japan, when I created it.
>> Commands (@fladdict)
>> Progression (@nium)

Thank you for reading it.