Sunday, 11 April 2010

Steve Jobs goes Crazy and the Net Freaks Out!

While many people were watching the return of Tiger Woods and Phil Mickelson's awesome win at the Masters, the Internets were freaking out about Apple's new license agreement for iPhone development.



The story was originally broken by Daring Fireball here. And has been commented on and expanded at the following sites. All three posts are awesome and I recommend you read each.

Adobe has been developing a tool to allow Flash developers to compile Flash applications for the iPhone OS.  Thus, Flash developers could completely bypass Apple tools or compilers to create their apps. By changing the license agreement, Apple has made this Adobe tool illegal on the iPhone platform. It also limits development to Objective C, C, C++, and HTML/Javascript on Webkit. So any cross platform compiler written in Ruby, or .Net would also be illegal. So as you might imagine, this has angered developers who were planning to use these 3rd party tools.



In my mind Apple has a point. They are trying to provide a simple, stable device with consistent interfaces. Nontechie's do not care if the platform is open or closed. Regular folks don't care about multitasking. They just want their phone to work all the time. PCs crash, phones don't. By tightly controlling design and development, Apple can meet their stability and design goals.



Google Android provides the open alternative to Apple's approach. Right now it is messier and probably not as good. But it is open, and that allows developers to iterate and improve. Over time, it seems possible that it will match or surpass its closed adversary.



Developers, customers, and the market will determine which approach is best. It is going to be an interesting fight.



Thursday, 8 April 2010

CSS: Center an Image with CSS

CSS ButtonI have created a short write up on how to center an image using CSS. Two methods are covered, using a div and defining rules for the img tag directly. Enjoy!

Wednesday, 7 April 2010

CodeIgniter Unit Testing

CodeIgniter includes a unit test library as part of the framework. Documentation is included with the standard docs. If you follow the instructions, you can set it up and use it quite easily. However, the default output format leaves a little bit to be desired. Each test generates a separate table. This quickly becomes unwieldy and not very useful as the more tests added create longer and longer pages.



To solve the problem modified the template a little so once a table is produced with a row for each test. Here is my code.



   1:  <h2>Unit Test Page</h2>
2: <p>This is the test page for the application.</p>
3:<?php
4:$str = '
5: <tr>
6: {rows}
7: <td style="border:1pt solid black;">{result}</td>
8: {/rows}
9: </tr>';
10:
11:$this->unit->set_template($str);
12:
13:// Sample Test 1
14:$test = 1 + 1;
15:$expected_result = 2;
16:$test_name = 'Adds one plus one';
17:$this->unit->run($test, $expected_result, $test_name);
18:
19:
20:?>
21:<table cellpadding="4" cellspacing="1" style="border:1pt solid black; font-size:9pt; width:625px">
22: <tr><th width="35%">Test Name</th><th>In Type</th><th>Test Type</th><th width="15%">Result</th><th width="0%">Path</th><th>No</th></tr>
23:<?php
24:// Create Report
25:echo $this->unit->report();
26:?>
27:</table>
28:
29:</body>
30:</html>


My template is defined on lines 4-9. Basically, we only want to output a row for each test. So lines 20-27 defines the table that contains the rows. This produces much more compressed output.

Tuesday, 6 April 2010

Hands on iPad

Well I finally got my hands on an iPad. It looks to be a very nice device for surfing. Plus I checked out some of the applications like the constellation app which is very cool.



I didn't care for the screen much. It has a very glossy finish and in the store it was hard to ignore all the glare. So that said, I think I'm gonna wait. I want to see some of the Google tablets before I make any decision.



The tablets are here to stay methinks. Now let the tablet wars begin!

Saturday, 3 April 2010

iPad finally Released!



After much hoopla, the Apple iPad was released today. Since I'm visiting my parents in Alamosa, I'm nowhere near any Apple store. I can't find any coverage online and such, but I did find this story from the Chicago Tribune with techies commenting on the impact of the new device.



The conversation seems to be clustering around the Apple closed store and single tasking OS versus Google Android and its open store and multitasking operating system. I tend to side with the open tribe. In the long run, more open systems and software win out. Is this the PC versus Mac battle all over again? But this time, it is smart phones and tablets. With a new iPhone coming out this summer and dozens of Android devices on the way, it is going to be an interesting next couple of years.

Friday, 2 April 2010

New Blogger Template Designer

Google LogoThe Google Blogger site is testing a new blog designer tool. I just noticed the announcement is a little old, but its new to me. So what's new about this design tool?



First a bunch of new templates for your blog. Very cool looking templates. In addition, the new template designer gives nondevelopers a lot more control over their templates. The main caveat? The new designs will not work on IE 6. But that is not really a big deal, because it is time to move beyond IE 6.

Thursday, 1 April 2010

Generate random number in Android

To generate random number in Android, class java.util.Random can be used.

This class java.util.Random provides methods that generates pseudo-random numbers of different types, such as int, long, double, and float.

It support two public constructor:
Random() - Construct a random generator with the current time of day in milliseconds as the initial state.
Random(long seed) - Construct a random generator with the given seed as the initial state.

Generate random number in Android

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Generate Random number"
android:id="@+id/generate"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/generatenumber"
/>
</LinearLayout>


AndroidRandom.java
package com.exercise.AndroidRandom;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class AndroidRandom extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final Random myRandom = new Random();

Button buttonGenerate = (Button)findViewById(R.id.generate);
final TextView textGenerateNumber = (TextView)findViewById(R.id.generatenumber);

buttonGenerate.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
textGenerateNumber.setText(String.valueOf(myRandom.nextInt()));
}});
}
}


Related:
- Generate sequence of Random number.