Friday, 8 October 2010

greenpois0n - get a dose on 10/10/10

Chronic Dev will be releasing greenpois0n on 10/10. This JB will include iPhone 4, iPod Touch 4, and iPad. As of now, it will not include any other device due to the changes from previous devices' bootroms. I've been busy helping Chronic Dev Team and will continue working on TinyUmbrella once we've released greenpois0n.

(Thanks OPK for the killer artwork)

Setting up a Mac 04: Fixing the Terminal and Bash

OS X pictureBeing a command line junkie, I find the default bash shell settings on the Mac need a few tweaks. Only two files need to be changed, the bash login configuration file (.bash_profile) and the bash run control file (.bashrc). A good explanation of both can be found here.



.bash_profile

The only change here is to call the .bashrc file on the login.

. .bashrc



This will load the settings in the .bashrc file every time the login shell is executed.



.bashrc

Two things to do in this file. Colorize the ls command and change the command prompt.



alias ls='ls -G'

alias ll='ls -lG'



export PS1='\w \$ '



The -G option colorizes the results. The PS1 changes the command prompt to show only the current directory and the dollar sign. This gets rid of rather long default host name.



If you want to change the host name, go to the sharing preferences and change the Computer Name. Then you can leave the prompt like this:

export PS1='\h:\w \$ '

How to create sub-folder in SD Card, using Java code

How to create sub-folder in SD Card, using Java code

If you want to create sub-folder in SD Card using Java code, you can use the mkdir() method of java.io.File class.



ex.

String newFolder = "/myFolder2";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myNewFolder = new File(extStorageDirectory + newFolder);
myNewFolder.mkdir();


And also, AndroidManifest.xml have to be modify to add permission of "android.permission.WRITE_EXTERNAL_STORAGE"
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exercise.AndroidNewFolder"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndroidNewFolder"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>



Related Article:
- Save file to SD Card
- How to create sub-folder in SD Card of Android Emulator, using adb

How to create sub-folder in SD Card of Android Emulator, using adb

If you want to create sub-folder in SD Card of Android Emulator, Android Debug Bridge(adb) can be used. Android Debug Bridge(adb) is a versatile tool lets you manage the state of an emulator instance or Android-powered device.



With Android Emulator running, start a Terminal (in Linux), switch to the <android sdk>/tools folder. type the command:

$./adb shell "mkdir /sdcard/myFolder"

where:
<android sdk> is the location of your installed android sdk.
myFolder is the folder you want to create.



Related article: Create SD Card in Android Emulator and copy files into, in Eclipse, Emulator and DDMS.

Thursday, 7 October 2010

Setting up a Mac 03: Web Browsers

OS X pictureThe first software I install is Web browsers. With the Mac, Safari is installed by default, so that is taken care of.



Firefox gets installed first, great for general web browsing and web development. The following addons are a must.



Flashblock - Prevents flash from running on a web page without your approval. Instead of flash, a flash icon is presented in a box where the flash would be. Click on the icon to load that flash element if your wish. The plugin prevents all those nasty CPU hogging flash ads from running. But just clicking allows you to run things like videos just fine.



Firebug - A web page debugger. A must for anyone developing a web site.



Chrome is next. Each tab has its own thread and runs really fast. Great for using Google sites too. There is also a FlashBlock for Chrome.



Lastly, SeaMonkey gets added. This is the real descendent of the old Netscape browser and uses the same rendering engine as Firefox. An integrated browser with built in mail and web page creation tool. In addition, this browser supports profiles. So if you have multiple Google accounts, for example, you can run a separate instance of the browser for each account.



For example, a shell script like this will run a new instance of the browser:



#!/bin/bash

/Applications/SeaMonkey.app/Contents/MacOS/seamonkey-bin -P profileName &

android.app.Service

android.app.Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Each service class must have a corresponding declaration in its package's AndroidManifest.xml. Services can be started with Context.startService() and Context.bindService(). (Ref: Service | Android Developers)

This exercise is a simple app with a dummy Local Service. Through the exercise, what can be noted are the life-cycle of a Service, how to link with Service with Start Service, Stop Service, Bind Service and Unbind Service, also the steps to implement the app with Service.

android.app.Service

Create a New Android Application as normal, with the main activity AndroidService.

Create a new class MyService extends Service. It's our service.
package com.exercise.AndroidService;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.widget.Toast;

public class MyService extends Service {

@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
Toast.makeText(this,
"-MyService.onBind()-", Toast.LENGTH_LONG).show();
return null;
}

@Override
public void onCreate() {
// TODO Auto-generated method stub
Toast.makeText(this,
"-MyService.onCreate()-", Toast.LENGTH_LONG).show();
}

@Override
public void onDestroy() {
// TODO Auto-generated method stub
Toast.makeText(this,
"-MyService.onDestroy()-", Toast.LENGTH_LONG).show();
}

@Override
public void onRebind(Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(this,
"-MyService.onRebind()-", Toast.LENGTH_LONG).show();
}

@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
Toast.makeText(this,
"-MyService.onStart()-", Toast.LENGTH_LONG).show();
}

@Override
public boolean onUnbind(Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(this,
"-MyService.onUnbind()-", Toast.LENGTH_LONG).show();
return false;
}

public class LocalBinder extends Binder{
MyService getService(){
return MyService.this;
}
}

}


Modify main.xml to have four button to involve our expected task, Start Service, Stop Service, Bind Service and Unbind Service.
<?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:id="@+id/startservice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start Service"
/>
<Button
android:id="@+id/stopservice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Stop Service"
/>
<Button
android:id="@+id/bindservice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Bind Service"
/>
<Button
android:id="@+id/unbindservice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Unbind Service"
/>
</LinearLayout>


Modify the main activity, AndroidService.java.
package com.exercise.AndroidService;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class AndroidService extends Activity {

private MyService myService;
private boolean serviceIsBinding;

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

Button buttonStartService = (Button)findViewById(R.id.startservice);
Button buttonStopService = (Button)findViewById(R.id.stopservice);
Button buttonBindService = (Button)findViewById(R.id.bindservice);
Button buttonUnbindService = (Button)findViewById(R.id.unbindservice);

buttonStartService.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startService();
Toast.makeText(AndroidService.this,
"Start Service", Toast.LENGTH_LONG).show();
}});

buttonStopService.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
stopService();
Toast.makeText(AndroidService.this,
"Stop Service", Toast.LENGTH_LONG).show();
}});

buttonBindService.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
bindService();
Toast.makeText(AndroidService.this,
"Bind Service", Toast.LENGTH_LONG).show();
}});

buttonUnbindService.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
unbindService();
Toast.makeText(AndroidService.this,
"Unbind Service", Toast.LENGTH_LONG).show();
}});
}

private ServiceConnection serviceConnection = new ServiceConnection(){

@Override
public void onServiceConnected(ComponentName arg0, IBinder arg1) {
// TODO Auto-generated method stub
myService = ((MyService.LocalBinder)arg1).getService();
Toast.makeText(AndroidService.this,
"onServiceConnected()", Toast.LENGTH_LONG).show();
}

@Override
public void onServiceDisconnected(ComponentName arg0) {
// TODO Auto-generated method stub
myService = null;
Toast.makeText(AndroidService.this,
"onServiceDisconnected()", Toast.LENGTH_LONG).show();
}};

private void startService(){
Intent intentService = new Intent(this, MyService.class);
this.startService(intentService);
}

private void stopService(){
Intent intentService = new Intent(this, MyService.class);
this.stopService(intentService);
}

private void bindService(){
Intent intentService = new Intent(this, MyService.class);
bindService(intentService, serviceConnection, Context.BIND_AUTO_CREATE);
serviceIsBinding = true;
}

private void unbindService(){
if(serviceIsBinding){
unbindService(serviceConnection);
serviceIsBinding = false;
}
}
}

In with, ServiceConnection is the interface for monitoring the state of an application service.

Finally, modify AndroidManifest.xml to add the <service> element.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exercise.AndroidService"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndroidService"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name="MyService"></service>
</application>
<uses-sdk android:minSdkVersion="7" />

</manifest>


Download the files.

Wednesday, 6 October 2010

Setting up a Mac 02: Bootcamp

OS X pictureIf you want to dual boot your shiny new Mac, you will need to install Bootcamp. Not one program, but a number of programs on both OS X and Mac, Bootcamp makes switching between the two operating systems a snap. This note is not a comprehensive guide to bootcamp, there are lots of docs on that, but a few tips from my experience.



What You Need to Start

Before you start the install, you will need a few things.

  1. First, you need a copy of Windows 7. I recommend the 64 bit version as this is gonna work best in the long run. If you know what your are doing, consider getting the System Builders version, it will save you a little money. If you want tech support, get the standard version linked here.




  2. Next, you need a wired connection to your Internet. Once my installation was done, the Wifi for the MacBook Pro did not work under Windows initially. This is not required but definitely makes things go smoother.

  3. A mouse. After the initial install, the track pad did not work completely. No right click for example. A simple 3 button mouse makes things a lot easier.

Bootcamp Installation
To start the installation, open Spotlight (Command Spacebar) and type boot. This should provide a link to the Bootcamp Assistant. Click on that and the assistant will walk your through the setup on the Mac side.



When you partition the drive, I would recommend a minimum of 80gig of space. Bootcamp assistant will name the new partition BOOTCAMP making it easy to know which partition to format when you install Windows.



Bootcamp will have you insert the install disc and will reboot and start the installation.


Once Windows Starts

Once Windows starts up, you need to install the Windows Bootcamp utilities. You will find these on your OS X operating system disc. This contains all the drivers and utilities to make your Mac work on Windows. Just insert the disc and run the installer.



Once the installation is complete, you should have all the drivers for your Mac installed. In addition, there will be a Bootcamp app in the system tray of your Windows system. At this point, you can proceed with your Windows patching and software installation.