Thursday, September 30, 2010

Arduino Bots and Gadgets




Make: Arduino Bots And Gadgets

Want to build your own robots, turn your ideas into prototypes, control devices with a computer, or make your own cell phone applications? It’s a snap with this book and the Arduino single-board microcontroller. Embedded systems are everywhere -- inside washing machines, cars, vacuum cleaners, and air conditioners. With Arduino, building your own embedded gadgets is easy, even for beginners.

This book gets you started with six fun projects: a stalker guard, robot insect, interactive painting, wireless smart home controller, boxing timer, and a cell phone controlled soccer robot. You’ll get impressive results quickly and gain the know-how and experience you need to invent your own gadgets.

  • Discover Arduino, the popular electronic prototyping platform
  • Get a great introduction to robots and electronic projects
  • Learn how to turn ideas into working physical prototypes
  • Use Android phones as key components in your projects
  • Get everyone involved with projects that even beginners can build




Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

Saturday, September 25, 2010

Android SDK Tools Revision 7 is available

SDK Tools, Revision 7 (September 2010) is available.



You can refer to my article to know how to Install Android SDK on Eclipse 3.5 Galileo, in Ubuntu 9.10. Or, if you have install Android 1.6 SDK or later version, you can refer to another article to upgrade Android SDK using Android SDK and AVD Manager.

Dependencies:

If you are developing in Eclipse with ADT, note that SDK Tools r7 is designed for use with ADT 0.9.8 and later. After installing SDK Tools r7, we highly recommend updating your ADT Plugin to 0.9.8.

General notes:
  • Added support for library projects that depend on other library projects.
  • Adds support for aidl files in library projects.
  • Adds support for extension targets in Ant build to perform tasks between the normal tasks: -pre-build, -pre-compile, and -post-compile.
  • Adds support for "headless" SDK update. See android -h update sdk for more information.
  • Fixes location control in DDMS to work in any locale not using '.' as a decimal point.

To determine what revision of the SDK Tools you are using, refer to the "Installed Packages" listing in the Android SDK and AVD Manager.




Thursday, September 23, 2010

android-ui-utils: Android UI Utilities


android-ui-utils is a set of utilities that help in the design and development of Android application user interfaces. This library currently consists of three individual tools for designers and developers:

1. UI Prototyping Stencils

2. Android Asset Studio

3. Android Icon Templates

WARNING: These utilities are currently in beta.

Project Home: http://code.google.com/p/android-ui-utils/

Android UI Utilities Beta Demo

A screencast demo of the the new Android UI Utilities project. This demo highlights the stencil kit for Pencil and the Android Asset Studio, both available at http://code.google.com/p/android-ui-u...

Thursday, September 9, 2010

How to set battery status of Android Emulator using the Emulator Console

In last two exercise "Detect Battery Level" and "Detect Battery Info", the apps about battery checking have been built. We have to set the battery status on Android Emulator to check our apps. To change the battery status on Android Emulator, Emulator Console can be used.

To connect to the console of any running emulator instance at any time, use this command:

telnet localhost <console-port>

Where <console-port> is the number shown on your emulator.

Details of the usage, refer to the section Using the Emulator Console of the document Android Emulator.

Wednesday, September 8, 2010

Detect Battery Info.

In the last exercise "Detect Battery Level", the app simple detect the battery level only. It's modified to have more info to be displayed, include: battery level, voltage, temperature, technology, charging status, and health of the battery.

Detect Battery Info.

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"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Info."
/>
<TextView
android:id="@+id/batterylevel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Level:"
/>
<TextView
android:id="@+id/batteryvoltage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Voltage:"
/>
<TextView
android:id="@+id/batterytemperature"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Temperature:"
/>
<TextView
android:id="@+id/batterytechology"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Technology:"
/>
<TextView
android:id="@+id/batterystatus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Status:"
/>
<TextView
android:id="@+id/batteryhealth"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Health:"
/>
</LinearLayout>


AndroidBattery.java
package com.exercise.AndroidBattery;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidBattery extends Activity {

private TextView batteryLevel, batteryVoltage, batteryTemperature,
batteryTechnology, batteryStatus, batteryHealth;


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

batteryLevel = (TextView)findViewById(R.id.batterylevel);
batteryVoltage = (TextView)findViewById(R.id.batteryvoltage);
batteryTemperature = (TextView)findViewById(R.id.batterytemperature);
batteryTechnology = (TextView)findViewById(R.id.batterytechology);
batteryStatus = (TextView)findViewById(R.id.batterystatus);
batteryHealth = (TextView)findViewById(R.id.batteryhealth);

this.registerReceiver(this.myBatteryReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}

private BroadcastReceiver myBatteryReceiver
= new BroadcastReceiver(){

@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub

if (arg1.getAction().equals(Intent.ACTION_BATTERY_CHANGED)){
batteryLevel.setText("Level: "
+ String.valueOf(arg1.getIntExtra("level", 0)) + "%");
batteryVoltage.setText("Voltage: "
+ String.valueOf((float)arg1.getIntExtra("voltage", 0)/1000) + "V");
batteryTemperature.setText("Temperature: "
+ String.valueOf((float)arg1.getIntExtra("temperature", 0)/10) + "c");
batteryTechnology.setText("Technology: " + arg1.getStringExtra("technology"));

int status = arg1.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN);
String strStatus;
if (status == BatteryManager.BATTERY_STATUS_CHARGING){
strStatus = "Charging";
} else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING){
strStatus = "Dis-charging";
} else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING){
strStatus = "Not charging";
} else if (status == BatteryManager.BATTERY_STATUS_FULL){
strStatus = "Full";
} else {
strStatus = "Unknown";
}
batteryStatus.setText("Status: " + strStatus);

int health = arg1.getIntExtra("health", BatteryManager.BATTERY_HEALTH_UNKNOWN);
String strHealth;
if (health == BatteryManager.BATTERY_HEALTH_GOOD){
strHealth = "Good";
} else if (health == BatteryManager.BATTERY_HEALTH_OVERHEAT){
strHealth = "Over Heat";
} else if (health == BatteryManager.BATTERY_HEALTH_DEAD){
strHealth = "Dead";
} else if (health == BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE){
strHealth = "Over Voltage";
} else if (health == BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE){
strHealth = "Unspecified Failure";
} else{
strHealth = "Unknown";
}
batteryHealth.setText("Health: " + strHealth);

}
}

};
}


Download the files.

Related Article:
- Home Screen Battery Widget



Tuesday, September 7, 2010

Detect Battery Level

It's a exercise of Android App to detect battery level.

Detect Battery Level

A BroadcastReceiver, myBatteryReceiver, is implemented and registered to receive ACTION_BATTERY_CHANGED, and retrieve "level" via getIntExtra() method.

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"
/>
<TextView
android:id="@+id/batterylevel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Level:"
/>
</LinearLayout>


AndroidBattery.java
package com.exercise.AndroidBattery;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidBattery extends Activity {

private TextView batteryLevel;

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

batteryLevel = (TextView)findViewById(R.id.batterylevel);
this.registerReceiver(this.myBatteryReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}

private BroadcastReceiver myBatteryReceiver
= new BroadcastReceiver(){

@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
int bLevel = arg1.getIntExtra("level", 0);

batteryLevel.setText("Battery Level: "
+ String.valueOf(bLevel) + " %");
}

};
}


Download the files.

Related Article: Detect Battery Info.

Thursday, September 2, 2010

Copy and Paste using ClipboardManager

ClipboardManager is a interface to the clipboard service, for placing and retrieving text in the global clipboard.

You do not instantiate this class directly; instead, retrieve it through getSystemService(String).

Copy and Paste using ClipboardManager

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"
/>
<EditText
android:id="@+id/src"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/dest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/copynpaste"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Copy'n Paste"
/>
</LinearLayout>


AndroidCopynPaste.java
package com.exercise.AndroidCopynPaste;

import android.app.Activity;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

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

final EditText src = (EditText)findViewById(R.id.src);
final TextView dest = (TextView)findViewById(R.id.dest);
Button copynPaste = (Button)findViewById(R.id.copynpaste);

final ClipboardManager clipBoard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);

copynPaste.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
clipBoard.setText(src.getText());
dest.setText(clipBoard.getText());

}});
}
}



Download the files.